I’ve got two programs. one is written in C, sending out structs of unsinged chars via serial port.
The other one is written in Java and supposed to receive this data.
I’m using the jSSC library which returns a byte array after reading from the serial port.
How can I now extract the original values?
what is send: 1,99,23,15,16,17,18
bytes I received: [B@c1c428
bytes converted to chars: [C@13526b0
Sending the data works correctly. I also wrote a C program to read the data which receives it correctly so the problem seems to be in the Java program.
System.out.println("Port " + PortName + " opened: " + serialPort.openPort());
//serialPort.setParams(9600, 8, 1, 0);
byte[] input;
if((input = serialPort.readBytes()) == null){
System.out.println("No data to be read");
System.exit(0);
}
char[] chars = new String(input).toCharArray();
System.out.println("Bytes read: " + input.length);
System.out.println("Byteoutput: " + input);
System.out.println("Charoutput: " + chars);
In order to actually output a byte array you need to do something like: