79644572

Date: 2025-05-29 20:18:56
Score: 0.5
Natty:
Report link
serial.write(b'\x03')

This may not work (or not work all the time) as it depends on the default encoding. If this is NOT utf-8 then pyserial will complain with the message :

TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))

To avoid this you have to encode your string as utf-8, so to send an escape sequence (e.g. ESC [ z ) you can do:

ESC_CHAR = chr(27)
text=f"{ESC_CHAR}[z".encode("utf-8"
serial.write(text)

You can of course compress this to one line or a variable for convenience.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: series80