2016-04-06 8 views
1

inpout32(http://www.highrez.co.uk/downloads/inpout32/)のJava実装であるjnpout32reg(http://www.hytherion.com/beattidp/comput/pport.htm)パッケージを使用してパラレルポートと通信しようとしています。私は完全に動作するように見えるパラレルポートテスター(ダウンロード.cnet。com/Parallel-Port-Tester/3000-2086_4-75940249.html)でinpout32をテストしました。しかし、Javaの実装は動作していないようです。jnpout32pkg/jnpout32regとのパラレルポート通信

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などを返します)から読み取ることができます。しかし、私は出力を書くことはできません。エラーは発生しませんが、受信側では何も起こりません(Parallel Port Testerではなく)。

私が代わりにjnpout32pkg(jnpout32regの異なるバージョン)を使用する場合、私は(私は同様にすべてのものをインストールしていても)次のエラーを取得する:

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

私が間違って何をやっている、と何の違いがありますpkgとreg?

答えて

0

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) 

あなただけp.Out32(address,0)続く、sleep(0.002)を使用し、(すなわち、直後に戻って0に設定)のパルスを送信する場合。続いて、次のコードで行われているJavaを介してこのスクリプトを実行します。アドレスは、パラレルポートアドレス(は0x378)で、numがに-書き込まれた値である

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

します。