2012-05-10 15 views
1

私は、マイクロコントローラ にデータを送信するためにJavaライブラリrxtxxを使用しています。アプリケーションは動作しているようですが、警告が表示されます:rxtxx2.1.7 version mismatch 送信データに影響しますか? 私はそれをテストしているが、何のデータが私のコードがある送信されませんでした:javaを使用してusbシリアルケーブルで接続する

import java.util.*; 
import gnu.io.*; 
import java.io.*; 



public class portwrit{ 
    static Enumeration  portList; 
    static CommPortIdentifier portId; 
    static String msgstr="100"; 
    static SerialPort   serialPort; 
    static OutputStream  outputStream; 
    static InputStream inputStream; 
    static Thread readThread; 


    static boolean  outputBufferEmptyFlag = false; 

    public static void main(String[] args) throws NoSuchPortException, PortInUseException { 
    boolean portFound = false; 
    String defaultPort = "COM6"; 


    portList = CommPortIdentifier.getPortIdentifiers(); 

    while (portList.hasMoreElements()) { 
     portId = (CommPortIdentifier) portList.nextElement(); 

     if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { 

     if (portId.getName().equals(defaultPort)) { 
      System.out.println("Found port " + defaultPort); 
      portFound = true; 
      try { 
      serialPort = 
       (SerialPort) portId.open("SimpleWrite", 2000); 
      } catch (PortInUseException e) { 
      System.out.println("Port in use."); 
      continue; 
      } 

      try { 
      outputStream = serialPort.getOutputStream(); 
      } catch (IOException e) {} 

      try { 
      serialPort.setSerialPortParams(9600, 
           SerialPort.DATABITS_8, 
           SerialPort.STOPBITS_1, 
           SerialPort.PARITY_NONE); 
      } catch (UnsupportedCommOperationException e) {} 

      try { 
       serialPort.notifyOnOutputEmpty(true); 
      } catch (Exception e) { 
      System.out.println("Error setting event notification"); 
      System.out.println(e.toString()); 
      System.exit(-1); 
      } 

      System.out.println(
       "Writing "+msgstr+"\" to "+serialPort.getName()); 
      try { 
      outputStream.write(Byte.parseByte(msgstr)); 
      } catch (IOException e) {} 

      try { 
       Thread.sleep(2000); // Be sure data is xferred before closing 
      } catch (Exception e) {} 
      serialPort.close(); 
      System.exit(1); 

     } 
     } 
    } 

    if (!portFound) { 
     System.out.println("port " + defaultPort + " not found."); 
    } 
    } 


} 

答えて

0

this articleによると、インストールしRXTXソフトウェアの複数のコピーを有することができます。あなたのパス/クラスパスでcomm.jarやRXTXcomm.jarなどを探していることを示唆しています。

+0

おかげさまで本当に助かりました。私はそれを試してみます –

+0

私はこのパッケージを試しました:http://pharos.ece.utexas.edu/wiki/images/7/7e/Ch-rxtx-2.2-20081207-win- x64.zip私はそれが動作するかどうかは知りませんが、警告はありがとう –

関連する問題