I am trying to develop a binary serial protocol for my device, and wanted to use PIO Serial Monitor with custom filters to aid in that development, but so far it has only been a hindrance.
It seems that the API for filters assumes the serial data is some form of text, and therefore must have an associated encoding (defaulting to utf-8). Is there any way to specify non-text-encoded, raw binary?
I know I can change the encoding with platformio.ini setting
monitor_encoding, but platformio docs don’t specify what all the possible options are (I guess it corresponds with the list here? 6.6. codecs — Codec registry and base classes — Python v3.2.6 documentation )
Even so, I don’t think I want to specify an encoding at all, since that would mean it is some kind of text representation.
Even the builtin
hexlify filter is unusable for me because all data is forced to be interpreted as utf-8.
As far as I can tell, when being sent arbitrary bytes, many sequences are seen as invalid utf-8, and get replaced with the unicode replacement character
hexlify prints as
?? because the “byte value” from
serial.iterbytes is greater than 255.
Having a value greater than 255 is completely nonsensical if you are trying to process raw bytes from the very start.
There is also a
monitor_raw setting, but that gives an error if attempted to use with a