Closed indiika closed 2 years ago
Try not calling setComPortTimeouts
in your event handler...this is causing the port to get reconfigured every time data is received which could definitely be causing problems. If the problem persists, it may be helpful to print out the actual received bytes in hex and compare them to what you are seeing in Device Monitoring Studio so that we can see what is truly being received instead of the UTF-8 converted version of it.
public static void main(String[] args) {
System.out.println("Hello world");
SerialPort[] ports = SerialPort.getCommPorts();
for (SerialPort port : ports) {
System.out.println(port.getSystemPortName());
if (port.getSystemPortName().equals("COM6")) {
//----------------------------------------------------------------
SerialPort comPort = port;
comPort.openPort();
comPort.addDataListener(new SerialPortDataListener() {
@Override
public int getListeningEvents() {
return SerialPort.LISTENING_EVENT_DATA_RECEIVED;
}
@Override
public void serialEvent(SerialPortEvent event) {
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_RECEIVED) {
return;
}
try {
byte[] byteArray = event.getReceivedData();
for (byte b : byteArray) {
String st = String.format("%02X", b);
System.out.print(st + ",");
}
} catch (Exception e) {
System.out.println(" " + e.toString());
}
}
});
//----------------------------------------------------------------
}
}
}
Please re-test your application using the newly released library version 2.8.0, although I don't expect it will solve your problem. It looks more like there is some sort of baud rate or flow control mismatch between your device and your port configuration. Please report back once you've re-tested. Thanks!
Chech port settings, mainly port speed, I think speed is different on host pc and your device
Hi hedgecrw many thanks for the response. Instead byte array I used line reader and got it working. Cheers !
Great, thanks!
Hi all, I'm trying to read a device output using JSC, According to device specification it sends ASCHII stream via serial port, Also I tried device monitoring studio to read the com output and row data set receive like bellow,
....... WBC 4.3910^9/l[4.00-10.00] LYM-0.6810^9/l[1.30-4.00] MON 0.4810^9/l[0.15-0.70] GRA 3.2310^9/l[2.50-7.50] LY%-15.5%[25.0-40.0] MO%+10.9%[ 3.0- 7.0] GR% 73.6%[50.0-75.0] RBC-3.6910^12/l[4.00-5.50]
................
But when I try to capture same using jSerialComm output is not readable,
e.g. �ooSW��w��
I used bellow code as well as various other available samples.
public static void main(String[] args) {
Can someone kindly help me to read expected data using the library