Java 与JNPOUT32PGG/jnpout32reg的并行端口通信
我试图通过包jnpout32reg()与并行端口通信,jnpout32reg()是Input32()的Java实现。我用一个并行端口测试仪(download.cnet.com/Parallel-Port Tester/3000-2086_4-75940249.html)测试了Input32,它似乎工作得很好。但是,java实现似乎不起作用Java 与JNPOUT32PGG/jnpout32reg的并行端口通信,java,c++,parallel-processing,java-native-interface,parallel-port,Java,C++,Parallel Processing,Java Native Interface,Parallel Port,我试图通过包jnpout32reg()与并行端口通信,jnpout32reg()是Input32()的Java实现。我用一个并行端口测试仪(download.cnet.com/Parallel-Port Tester/3000-2086_4-75940249.html)测试了Input32,它似乎工作得很好。但是,java实现似乎不起作用 package ioTest_reg; import hardware.jnpout32.*; public class ioTestReg {
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();
}
}
我做错了什么,pkg和reg有什么区别?在亚历山大·海梅尔()和道格拉斯·贝蒂()的大力帮助下,我终于找到了解决办法 Python对Input32(或Inputx64,取决于您使用的版本)没有问题,因此我编写了以下脚本
# 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(地址,0)
。接下来,您将通过Java执行此脚本,这是通过以下代码完成的:
String cmd = "python C:\\Path\\To\\Code\\WriteParPort.py "+ address +" " + num;
Process p = Runtime.getRuntime().exec(cmd);
其中address是并行端口地址(0x378),num是要写入的值 在Alexander Heimel()和Douglas Beattie()的大力帮助下,我终于找到了解决办法 Python对Input32(或Inputx64,取决于您使用的版本)没有问题,因此我编写了以下脚本
# 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(地址,0)
。接下来,您将通过Java执行此脚本,这是通过以下代码完成的:
String cmd = "python C:\\Path\\To\\Code\\WriteParPort.py "+ address +" " + num;
Process p = Runtime.getRuntime().exec(cmd);
其中address是并行端口地址(0x378),num是要写入的值