0

So, I'm porting a script that read a serial port using pySerial into micropython.

The serial reading works fine but I came across the issue that MicroPython seems to not support .hex() operations on bytes object.

On my Python 3.9 script, I receive bytes and then split them into a string spaced by - with the code

str(data_raw.hex('-'))

Now, from what I have understood MicroPython doesn't support it. I have found out this function but I would lose the option to separate the bytes with -

Is there a workaround for it?

NicoCaldo
  • 1,171
  • 13
  • 25

1 Answers1

2

You can use binascii.hexlify with a seperator:

>>> binascii.hexlify(b"TEST", "-").decode()
'54-45-53-54'
HTF
  • 6,632
  • 6
  • 30
  • 49