使用jnpout32pkg/jnpout32reg的并行端口通信 [英] Parallel Port Communication with jnpout32pkg / jnpout32reg

查看:145
本文介绍了使用jnpout32pkg/jnpout32reg的并行端口通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过软件包jnpout32reg与并行端口进行通信( http://www.hytherion.com/beattidp/comput/pport.htm ),是inpout32的Java实现(

I am trying to communicate with a Parallel Port via the package jnpout32reg (http://www.hytherion.com/beattidp/comput/pport.htm), a Java implementation of inpout32 (http://www.highrez.co.uk/downloads/inpout32/). I have tested inpout32 with a Parallel Port Tester (download. cnet. com/Parallel-Port-Tester/3000-2086_4-75940249.html), which seems to work perfectly. However, the java implementation does not seem to work.

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,等等.).但是,我不能写输出.没有给出错误,但是在接收端没有任何反应(与并行端口测试器相反).

The connection with the port is made and I can read from the ports (Port 378 returns 78, 379 returns 79 etc...). However, I cannot write output. No error is given, but nothing happens on the receiving side (as opposed to with the Parallel Port Tester).

当我改用jnpout32pkg(jnpout32reg的另一个版本)时,出现以下错误(即使我安装了所有类似的东西):

When I use jnpout32pkg (a different version of jnpout32reg) instead, I get the following error (even though I installed everything similarly):

 Exception in thread "main" java.lang.UnsatisfiedLinkError:  ioTest_pkg.jnpout32.ioPort.Out32(SS)V

我做错了什么,pkg和reg有什么区别?

What am I doing wrong, and what is the difference between pkg and reg?

推荐答案

在Alexander Heimel(

With some great help from Alexander Heimel (http://csflab.nin.knaw.nl/protocols/parallel-port-in-matlab) and Douglas Beattie (http://www.hytherion.com/beattidp/comput/pport.htm) I finally managed to find a workaround.

Python的inpout32(或inpoutx64,取决于您使用的版本)没有问题,因此我编写了以下脚本.

Python has no problem with inpout32 (or inpoutx64, depending on the version you use), so I wrote the following script.

# 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执行此脚本,该脚本使用以下代码完成:

If you only want to send a pulse (i.e. set it back to 0 immediately afterwards), use sleep(0.002), followed by p.Out32(address,0). Following, you execute this script via Java, which is done with the following code:

String cmd = "python C:\\Path\\To\\Code\\WriteParPort.py "+ address +" " + num;
Process p = Runtime.getRuntime().exec(cmd);

其中的地址是并行端口地址(0x378),而num是要写入的值.

In which address is the parallel port address (0x378), and num is the to-be-written value.

这篇关于使用jnpout32pkg/jnpout32reg的并行端口通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆