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 1.5.2.31. 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:
…
try:
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,
…
try:
value = system.serial.readBytes(event.source.parent.comPort,20,10)
event.source.parent.dataInA = value
…
The string returned in value is:
ICAgQ1RBICAgICAgICA4ODkyDQo
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.