2

I'm trying to send/receive data with an embedded device using a custom protocol. struct.pack() and unpack() seem like they'd do the job, but the fmt argument doesn't seem to be flexible enough to handle variable length arrays of data.

Example: device sends [event report] [number of events] ([event type] [event value], [event type] [event value], ...)

Where:

  • event report (unsigned 8-bit)
  • number of events (unsigned 16-bit)
  • event type (unsigned 8-bit)
  • event value (signed 16-bit)

What would be the best way to decode this data into Python? Also, how would I encode similar data structures to send to the device?

asked May 12, 2013 at 21:30

1 Answer 1

3

Consider using python-bitstring to implement binary protocols. It's quite flexible and easy to use.

answered May 12, 2013 at 21:35
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.