0

我有 Gemalto BGS5T java 模块和 1 线温度传感器。我有使用 RS232 端口与温度传感器通信的 java midlet。但问题是,无论我发送什么,我都没有收到传感器的响应。传感器上有正确的电压,所以连接应该没问题。我尝试测试我的程序,以便将 rs232 端口连接到计算机并使用终端(白蚁)观察发送的数据是否正确并且一切看起来都应该正确。另一个测试是我将温度传感器直接连接到计算机并使用终端发送数据,它的工作原理应该是这样。我什至得到了一些随机输入的响应,例如 9999。我检查了终端内的连接参数并将它们复制到 java midlet,但没有成功。只有一次我得到了一些回应,但是当我第二天尝试继续工作时,我没有成功。终端内部参数:波特率:9600 数据位:8 停止位:1 奇偶校验:无 流量控制:RTS/CTS

这是Java代码:

String strCOM = "comm:COM0;blocking=on;baudrate=9600";
commConn = (CommConnection)Connector.open(strCOM);
System.out.println("CommConnection(" + strCOM + ") opened");
System.out.println("Real baud rate: " + commConn.getBaudRate());
inStream  = commConn.openInputStream();
outStream = commConn.openOutputStream();
System.out.println("InputStream and OutputStream opened");
while(1==1)
    {
        byte bC1 = (byte)Integer.parseInt("11000001",2);
        byte C1 = hexToBin("C1");
        byte bparameter2 = (byte)Integer.parseInt("00010111",2);
        byte bparameter3 = (byte)Integer.parseInt("01000101",2);
        byte bparameter4 = (byte)Integer.parseInt("01011011",2);
        byte bparameter5 = (byte)Integer.parseInt("00001111",2);
        byte bparameter6 = (byte)Integer.parseInt("10010101",2);
        byte[] bArray = {bparameter2,bparameter3,bparameter4,bparameter5,bparameter6};





      int ch;
      try {
        outStream.write(bC1);
        Thread.sleep(50);
        //outStream.write(bArray);
        outStream.write(bparameter2);
        outStream.write(bparameter3);
        outStream.write(bparameter4);
        outStream.write(bparameter5);
        outStream.write(bparameter6);

        System.err.println("inStream bytes:" + inStream.available());
        if(inStream.available() > 0)
        {   
          String msg = "";
          while(inStream.available() > 0)
          {
            ch = inStream.read();
            msg = msg + (char) ch;
          }
          System.out.println("Serial msg: " + msg);
        }
        outStream.write('9');
        outStream.write('9');
        outStream.write('9');
        outStream.write('9');
        Thread.sleep(100);
        outStream.write('9');
        outStream.write('9');
        outStream.write('9');
        outStream.write('9');
        System.err.println("inStream bytes:" + inStream.available());
        if(inStream.available() > 0)
        {   
          String msg = "";
          while(inStream.available() > 0)
          {
            ch = inStream.read();
            msg = msg + (char) ch;
          }
          System.out.println("Serial msg: " + msg);
        }
4

1 回答 1

1

我必须使用零调制解调器电缆才能使其正常工作。

于 2015-02-15T17:51:36.390 回答