I am trying to test the data obtained from a serial port and it can not be found correct. I need to check whether the first byte obtained in the packet is 0xBE:
#ser pyserial serial object data = ser.read (5) print "serial RX:" + binascii .b2a_hex ( Data) if data [0]! = 0xBE: Print "wrong value" always prints:
Serial RX: beef000008 wrong value Even if the binary to print ascii shows that the correct value has been received.
Where am I actually going wrong in this basic work?
Thank you, Robin.
From
:
changed to version 2.5: when available Returns an example of bytes (Python 2.6 and newer) and otherwise str so I tested:
& gt; & Gt; Bytes (0xbe) == 0xbe incorrect But if you convert it to int:
& gt; & Gt; Int (bytes (0xbe)) == 0xbe True As it shows, type is included by [PEP-3137]. This is for Python 3, but there is only one surname for str . So, basically, while treating the output of pyserial as a str , again python2 codes are done.
No comments:
Post a Comment