python - Byte manipulation (Serial Data) Raspberry Pi -


im trying establish rs485 communication system between raspberry pi , arduino. im using nick gammons arduino 485 library arduino rs485 library , port on python run on raspberry pi.

the transmission side of things working fine crc8 , complement error prevention working im having difficulty receiving side of things. documented in pyserial api here ser.read() returns variable of type bytes. problem require bitwise operations perform error checks example:

            in_byte = ser.read()               if (in_byte >> 4) != ((in_byte & 0x0f) ^ 0x0f):                 return 0              in_byte >>= 4 

this of course throws interpretor error saying bitwise operator '>>' not compatible variables of type int , bytes

i know of int.from_bytes method seems require multiple bytes plus endian format

what 'correct' or typical way should perform bitwise operations on byte byte serial data?

im relatively new python coming c / c++ background,

thanks

andy

short answer:

ord() function works great single bytes ex:

        temp = ser.read()         in_byte = ord(temp) 

tldr:

using python struct.unpack 1-byte variables


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -