Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.35k stars 287 forks source link

Issues with Baud Rate greater than 9600 #317

Closed sim-pixel closed 2 years ago

sim-pixel commented 4 years ago

I am testing jSerialComm in an application in Java but when I set a baud rate higher than 9600 I cannot read data: I receive "00" packets with no apparent logic. So far i have used baud rate of 1200-2400-4800-9600 and have not encountered any problems.

Below is my code:

     com.fazecast.jSerialComm.SerialPort userPort = com.fazecast.jSerialComm.SerialPort.getCommPort("COM16");
     userPort.setComPortParameters(115200, 8, 1, SerialPort.NO_PARITY);

     //Initializing port
     userPort.openPort();
     if (userPort.isOpen()) {
     System.out.println("Port initialized!");
     } else {
     return;
     }

    userPort.addDataListener(new com.fazecast.jSerialComm.SerialPortDataListener() {
        @Override
        public int getListeningEvents() {
              return com.fazecast.jSerialComm.SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
        }
    public void serialEvent(com.fazecast.jSerialComm.SerialPortEvent event) {
          if (event.getEventType() != com.fazecast.jSerialComm.SerialPort.LISTENING_EVENT_DATA_AVAILABLE) {
                  return;
              }     

              byte[] newData = new byte[userPort.bytesAvailable()];
              parseData(newData);
        }
    });

Any suggestion? Thank you in advance.

hedgecrw commented 3 years ago

Have you ensured that the device you are communicating with supports baud rates higher than 9600? Receiving random 00 packets at higher baud rates indicates that the library is trying to make sense of garbage data due to a mismatch between the supported transmission speeds on the receiving and transmitting devices.

hedgecrw commented 2 years ago

Closing due to inactivity and most likely not a bug due to this being the only issue raised about this after many years.