I am working with some hardware that can be controlled via hex commands. I already have some snippets of Python code I use for telnet control of other devices that use ASCII commands.
How do I go about sending hex commands? For instance, how would I modify skt.send('some ascii command\r') with hex value, and what’s the best data type for storing those values?
Thanks.
In Python 2, use string literals:
In Python 3, use bytes literals or
bytes.fromhex:In either case, the
bytearraytype will probably be useful as it is a mutable (modifiable) type that you can construct with integers as well as a bytes literal: