与jnpout32pkg/jnpout32 reg的并行端口通信
Parallel Port Communication with jnpout32pkg / jnpout32reg
我正试图通过包jnpout32reg与并行端口通信(http://www.hytherion.com/beattidp/comput/pport.htm),inpout32的Java实现(http://www.highrez.co.uk/downloads/inpout32/)。我已经用并行端口测试仪测试了inpout32(下载.cnet.com/Parallel Port Tester/3000-2086_4-75940249.html),它似乎工作得很好。然而,java实现似乎不起作用。
package ioTest_reg;
import hardware.jnpout32.*;
public class ioTestReg
{
static short datum;
static short Addr;
static pPort lpt;
static void write()
{
datum = 0x001;
// Notify the console
System.out.println("Write to Port: " + Integer.toHexString(Addr) +
" with data = " + Integer.toHexString(datum));
//Write to the port
long start = System.currentTimeMillis();
long stop = System.currentTimeMillis();
while (stop-start < 10000){
lpt.output((short)0x001);
stop = System.currentTimeMillis();
}
System.out.println("Finished");
}
static void do_read_range()
{
// Try to read 0x378..0x37F, LPT1:
for (Addr=0x378; (Addr<0x380); Addr++) {
//Read from the port
datum = (short) lpt.input(Addr);
// Notify the console
System.out.println("Port: " + Integer.toHexString(Addr) +
" = " + Integer.toHexString(datum));
}
}
public static void main( String args[] )
{
lpt = new pPort();
Addr=0x378;
datum=0x01;
write();
// Try to read 0x378..0x37F, LPT1:
do_read_range();
}
}
与端口的连接已建立,我可以从端口读取(端口378返回78,379返回79等)。但是,我无法写入输出。没有给出任何错误,但接收端没有发生任何事情(与并行端口测试仪相反)。
当我使用jnpout32pkg(jnpout32\reg的另一个版本)时,我会收到以下错误(尽管我安装的所有东西都是类似的):
Exception in thread "main" java.lang.UnsatisfiedLinkError: ioTest_pkg.jnpout32.ioPort.Out32(SS)V
我做错了什么?pkg和reg之间有什么区别?
在Alexander Heimel的大力帮助下(http://csflab.nin.knaw.nl/protocols/parallel-port-in-matlab)和Douglas Beattie(http://www.hytherion.com/beattidp/comput/pport.htm)我终于找到了一个变通办法。
Python对inpout32(或inpoutx64,具体取决于您使用的版本)没有问题,所以我编写了以下脚本。
# import windll, to be able to load the inpoutx64.dll/inpout32.dll file
from ctypes import windll
import sys
from time import sleep
## If no input is given, write '1' to parallel port
address = int(888) # 0x378 in hex
num = 1
## if two inputs are given
if len(sys.argv) > 2:
# cast string arguments to:
address = int(sys.argv[1],16) # hexadecimal integer
num = int(sys.argv[2]) # decimal integer
# load dll.
# Select either inpout32.dll or inpoutx64.dll, depending on which
# Python version you use. If you get the error:
# WindowsError: [Error 193] %1 is not a valid Win32 application
# You have used the wrong one.
p = windll.LoadLibrary("C:\Python27\DLLs\inpout32.dll")
# write data
p.Out32(address,num)
如果您只想发送脉冲(即之后立即将其设置回0),请使用sleep(0.002)
,然后使用p.Out32(address,0)
。接下来,您将通过Java执行此脚本,该脚本使用以下代码完成:
String cmd = "python C:\Path\To\Code\WriteParPort.py "+ address +" " + num;
Process p = Runtime.getRuntime().exec(cmd);
其中,address是并行端口地址(0x378),num是要写入的值。
- UDP客户端/服务器程序在不同的IP和端口上通信超过2个插座
- 对传统串行端口通信进行逆向工程
- 串行通信 c++ 串行端口类
- 并发::并行端口开销和性能命中率(经验法则)
- UDP通信中的端口和IP地址用法
- 通过COM端口与ModEEG通信
- C、 通过USB适配器(LINUX)在并行端口上编写C++
- 如果我得到CE_FRAME错误,com端口通信有什么问题
- 基本串行端口通信Visual Studio C++(在浏览现有示例中时遇到问题)
- 串行端口通信
- 需要有关在C++/CLI中通过串行端口进行通信的建议
- Win32上FILE_FLAG_OVERLAPPED的COM端口通信永远挂起
- 与jnpout32pkg/jnpout32 reg的并行端口通信
- 串行端口通信 - PuTTY 仿真
- 将文件写入并行端口挂起
- Qt串行端口通信
- 无法与服务器正在侦听的端口通信
- 读取并行端口状态(简单的Push开关)
- PHP - c++ -实时端口通信
- Visual c++并行端口控制