Issue with readBytes

I am testing system.serial.readBytes. I am experiencing an issue with data returned. I have a serial monitor between the devices and have verified that the device is returning expected data. However, using readBytes the data is garbled. Additionally, I ran a test using readLine in place of readBytes in the same code segment and it works fine. I am using serial module version The code is a command out/response in scheme. i.e. command out = ‘TA*’, device response upon receiving command. The device we are testing is a red lion cub 5 counter with RS232. The data returned from the device is 20 bytes in length, this includes terminating .

The readLine code fragment is:

value = system.serial.readLine(event.source.parent.comPort,10)
event.source.parent.dataInA = value

The string returned in value is the expected:
CTA 6763
Note: any data enclosed by <> is a substitution of the actual byte for clarity in reading string.

When using readBytes in place of readLine implemented as follows,

value = system.serial.readBytes(event.source.parent.comPort,20,10)
event.source.parent.dataInA = value

The string returned in value is:

In both cases there were no changes with initializing and open/closing the port. readLine appears to work as expected, readBytes does not.

I have experimented with changing the timeout, but it does not appear to affect the quality of the return string.

Does system.serial.readBytesAsString() return the value you’re expecting?

I just tested ‘readBytesAsString’ and it works fine as opposed to ‘readBytes’.

readBytes() returns a java.lang.byte[], so whatever you’re stuffing that into is probably not interpreting or displaying it properly. readBytesAsString() converts that byte[] into a String before returning it.

It is being stuffed into a custom property of type string.

Yeah, that wouldn’t (and shouldn’t) work. You would have to convert it to a String first. Or use readBytesAsString().