Windows pyboard serial_number from python?
Posted: Mon Jul 16, 2018 2:16 am
I'm trying to uniquely identify a pyboard's COM port from the OS.
So essentially comport_of_pyboard('3976346C3436') returns 'COM3' (or None, if the requested pyboard is not connected)
I can get what I need on Linux with:
>>> from serial.tools.list_ports import comports
>>> ports = comports()
>>> ports
[<serial.tools.list_ports_common.ListPortInfo at 0x26cfac9f080>]
>>> com = ports[0]
>>> com.device
'/dev/ttyACM0'
>>> com.serial_number
'3976346C3436'
But the same code on Windows 10:
>>> from serial.tools.list_ports import comports
>>> ports = comports()
>>> ports
[<serial.tools.list_ports_common.ListPortInfo at 0x26cfad57518>]
>>> com = ports[0]
>>> com.device
'COM3'
>>> com.serial_number
'6'
If I manually browse the Device Manager:
<computer> > Ports (COM & LPT) > USB Serial Device (COM3) [double-click]
Details [tab] > Property: Parent
has the value: USB\VID_F055&PID_9800\3976346C3436
So Windows has the same information Linux has, just in a different format (no surprise there)
I think there's a way to do it through the registry (I'll post what I find), but has anyone got a more elegant solution?
So essentially comport_of_pyboard('3976346C3436') returns 'COM3' (or None, if the requested pyboard is not connected)
I can get what I need on Linux with:
>>> from serial.tools.list_ports import comports
>>> ports = comports()
>>> ports
[<serial.tools.list_ports_common.ListPortInfo at 0x26cfac9f080>]
>>> com = ports[0]
>>> com.device
'/dev/ttyACM0'
>>> com.serial_number
'3976346C3436'
But the same code on Windows 10:
>>> from serial.tools.list_ports import comports
>>> ports = comports()
>>> ports
[<serial.tools.list_ports_common.ListPortInfo at 0x26cfad57518>]
>>> com = ports[0]
>>> com.device
'COM3'
>>> com.serial_number
'6'
If I manually browse the Device Manager:
<computer> > Ports (COM & LPT) > USB Serial Device (COM3) [double-click]
Details [tab] > Property: Parent
has the value: USB\VID_F055&PID_9800\3976346C3436
So Windows has the same information Linux has, just in a different format (no surprise there)
I think there's a way to do it through the registry (I'll post what I find), but has anyone got a more elegant solution?