I try to communicate with an EEPROM using an F&C SAM3X. The device I try to read is configured to wait for incoming bytes. First byte is the command, the second byte is the position to read. As I have several positions to read I use integers in the program to indicate the position I want to read. Therefore I have to convert this integer into a byte to send it to the EEPROM. My program looks like this:
def _send(ser, cmd, pos = None, discard_resp = False):
try: pos = struct.pack('b', pos) except Exception as e: print('Did not work: ', e) try: digitalWrite(settings.pin_RS, HIGH) ser.write(cmd) ser.write(pos) return _read(ser,260) except Exception as e: print(e)
calling the function with pos=2 and listening to my RS-interface with my laptop leads to the following results:
the command is written correctly.
the position is written as 0x82 instead of 0x02
I tried the same function using the python installed on my laptop and there the conversion workes.
Did I miss something in the description in the lib or why is the first bit after the struct.pack inverted?
Thanks in advance for your help!