Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to receive byte strings #33

Open
iFreilicht opened this issue Nov 20, 2017 · 4 comments
Open

Add ability to receive byte strings #33

iFreilicht opened this issue Nov 20, 2017 · 4 comments

Comments

@iFreilicht
Copy link

iFreilicht commented Nov 20, 2017

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.

iFreilicht added a commit to iFreilicht/PyCmdMessenger that referenced this issue Nov 20, 2017
Very useful for raw data. Sending and receiving will not format the input data in any way.
Fixes harmsm#33
@ilovetogetspamed
Copy link

Any ETA on when this Pull Request is going to be added? I could really use this feature for 1-Wire addresses which look like '\x12\x5C\xEC\xA0\x00\x00\x00\x80' (64-bits). Thanks.

@iFreilicht
Copy link
Author

It seems the author hasn't had time to respond to any issues for weeks. In the meantime, you could just clone from my fork and then set this original repo as the remote once the changes are merged.

@ilovetogetspamed
Copy link

ilovetogetspamed commented Dec 11, 2017 via email

@ehiverson
Copy link

ehiverson commented Jan 12, 2018

I'm trying to use this code with a teensy 3.6. I've made sure the baud rates all match between the ArduinoBoard class instance, the sketch on the teensy, and the pingpong_test.py script. Also, I updated the data type sizes of the ArduinoBoard class to match here: https://forum.pjrc.com/threads/36658-datatypes-bit-depth
But I keep getting errors from
struct.unpack
struct.error unpack requires a buffer of 2 bytes
I commented out the 'kBBool', 'kBByte', and 'kChar', and found that 'kBInt16' tests pass up to -65536, each showing 'caught overflow', which I'm not sure is good or bad, but then it fails again from struct.unpack.
Any reason the smaller types shouldn't be working?

EDIT: I had the wrong sketch uploaded onto the micro.
So now it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants