Skip to content

Add ability to receive byte strings #33

@iFreilicht

Description

@iFreilicht

Right now, it is impossible to receive arbitrary byte-strings.

I wrote a simple setup where my python-script sends the character '\xff' and the Arduino sends that back.

When a string is received where any characters are larger than 127, the receive() method fails:

  File "[...]", line 20, in <module>
    main()
  File "[...]", line 15, in main
    response = messenger.receive()
  File "[...]\Python\Python36-32\lib\site-packages\PyCmdMessenger\PyCmdMessenger.py", line 284, in receive
    received.append(self._recv_methods[arg_format_list[i]](f))
  File "[...]\Python\Python36-32\lib\site-packages\PyCmdMessenger\PyCmdMessenger.py", line 593, in _recv_string
    s = value.decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

So I propose adding the format character 'B' to indicate a byte string. This will receive the byte string just like _recv_string does, but will just return it without decoding it or stripping any character.

For sending, behaviour should be equivalent to 's' as that already works perfectly fine.

I'll implement this and create a pull request when I'm done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions