PySerial and reading binary data

When the device I'm talking to sends binary data, I can recover most of it. However, it always seems that some bytes are missing, replaced by non-standard characters. For example, one separate output is as follows:

\xc4\xa5\x06\x00.\xb3\x01\x01\x02\x00\x00\x00=\xa9

The period and equals character must be a traditional byte in hexadecimal format (I confirmed this in another application). Other times, I get other strange characters, such as ')' or 's'. These characters are usually found in the same place (which depends on the command sent to me on the device).

How can I fix this problem?

+5
source share
2 answers

Are you showing output using something like this ?:

print output

, . :

print output.encode('hex')

.

+11

@RichieHindle, , . ,

print ' '.join(map(lambda x:x.encode('hex'),output))
+1

All Articles