Skip to content
Discussion options

You must be logged in to vote

To extract values from a byte array, you can use struct module and the method struct.unpack() or struct.unpack_from(). You can look at the generic Python manual for instructions, how to use it.
Since you are only interested in DF3 and DF4, which have index 5 and 6 in the bytes/bytearray object, you can access them directly and as two integers as content[5] and content[6]. If these two form a 16 bit number, you can calculate that as e.g. content[5] * 256 + content[6]. That is more efficient than using struct. One would use the latter to unpack all values from the message, which then is more efficient and shorter.

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@keble6
Comment options

@karfas
Comment options

@keble6
Comment options

Comment options

You must be logged in to vote
4 replies
@keble6
Comment options

@karfas
Comment options

@keble6
Comment options

@robert-hh
Comment options

Answer selected by keble6
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants