What is the cross-platform method of enumerating serial ports in Python (including virtual ports)?

This is what I’ve been using. It’s a mashup of the methods I posted above. I’d still like to see better solutions, though. # A function that tries to list serial ports on most common platforms def list_serial_ports(): system_name = platform.system() if system_name == “Windows”: # Scan for available ports. available = [] for i … Read more

Convert an int value to unicode

In Python 2 – Turn it into a string first, then into unicode. str(integer).decode(“utf-8”) Best way I think. Works with any integer, plus still works if you put a string in as the input. Updated edit due to a comment: For Python 2 and 3 – This works on both but a bit messy: str(integer).encode(“utf-8”).decode(“utf-8”)

Python Serial: How to use the read or readline function to read more than 1 character at a time

I see a couple of issues. First: ser.read() is only going to return 1 byte at a time. If you specify a count ser.read(5) it will read 5 bytes (less if timeout occurrs before 5 bytes arrive.) If you know that your input is always properly terminated with EOL characters, better way is to use … Read more

tech