2016-09-22 7 views
2

私は持っているデバイスのシリアルポートにデータを送信しようとしています。私のPCでは、ターミナルアプリケーションからデータを受信しようとしています。デバイスはJ2MEを使用していますが、私がcomポートに接続するために使用しているコードを以下に示します。シリアルポートでデータを送信

public boolean connect() { 
    if (bConnected) { 
     return true; 
    } else { 
     try { 
      StringBuffer strCom = new StringBuffer(80); 
      strCom.append("comm:" + strCOMPort 
        + ";blocking=on;autocts=off;autorts=off;stopbits="); 
      //autocts=on;autorts=on; 
      strCom.append(stopbits); 
      strCom.append(";bitsperchar="); 
      strCom.append(bitsperchar); 
      //strCom.append(";parity="); 
      //strCom.append(parity); 
      strCom.append(";baudrate="); 
      strCom.append(baudrate); 

      commConn = (CommConnection) Connector.open(strCom.toString()); 
      writeStatusToFile(
        "CommConnection(" + strCom.toString() 
          + ") with device opened."); 
      strCom = null; 
      inStream = commConn.openDataInputStream(); 
      outStream = commConn.openOutputStream(); 
      inStream.skip(inStream.available()); 
      bConnected = true; 
      return true; 
     } catch (Exception IOe) { 
      writeStatusToFile(
          "Opening COM0 IOException :" + IOe.getMessage()); 
      return false; 
     } 
    } 
} 

シリアルポートにデータを書き込んでいるコードを以下に示します。

public void sendData(short[] message){ 
    String bytedata = ""; 
    try 
    { 
     System.out.println("Length of message array: " + message.length); 
     for(int i = 0; i<message.length; i++){ 
      System.out.println("Data: " +message[i]); 
      bytedata += message[i]; 
      outStream.write(message[i]); 
      System.out.println("Done"); 
     } 
    //outStream.write(message); 
    outStream.flush(); 
    } 
    catch(Exception ex) 
    { 
     System.out.println("Exception during sending bytes--->" + ex.toString()); 
     ex.printStackTrace(); 
    } 
      System.out.println(
      "Data flushed to output stream: " + bytedata); 
} 

デバイス用のCOM設定は、パリティはなし、ボーレートが4800で、COM0の文字8あたりビット及びストップビット(これらの値はグローバルに初期化される)1です。私は、COMポートからデータを受信して​​いる端末アプリケーションで同じものを設定します。

私が直面している問題は、シリアルポートに接続すると私のPCに何も受信しないということです。私はコードロジックに間違いがないかどうかを知りたい。問題の分析に役立つ提案はすべて歓迎します。他の情報が必要な場合は、そう言います。

答えて

0

この問題は、私のアプリケーションがアクセスしようとしていたシリアルポートがRS232タイプであり、このタイプのシリアルポートはスレッドがポートにアクセスすることを許可し、そこではログを見ることができなかったディスプレイに表示されます。 これは理由である解決策ではないことにご注意ください。

関連する問題