Python/Serial: Difference between revisions
< Python
(Created page with "== List Windows COM Ports == <pre> # https://stackoverflow.com/questions/12090503/listing-available-com-ports-with-python import serial.tools.list_ports for device in serial.tools.list_ports.comports(): #print(dir(device)) print(device) # COM9 - USB Serial Port (COM9) print(f'description: {device.description}') # USB Serial Port (COM9) print(f'device: {device.device}') # COM9 print(f'hwid: {device.hwid}') # USB VID:PID=0403:6011 SER=FT78U7W3C print(f'interfac...") |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 18: | Line 18: | ||
print(f'product: {device.product}') # None | print(f'product: {device.product}') # None | ||
print(f'serial_number: {device.serial_number}') # FT78U7W3C | print(f'serial_number: {device.serial_number}') # FT78U7W3C | ||
print(f'usb_description: {device.usb_description}') # | # print(f'usb_description: {device.usb_description}') # bound function - device.usb_description() - "COM9" | ||
print(f'usb_info: {device.usb_info}') # | # print(f'usb_info: {device.usb_info}') # bound function - device.usb_info() - "USB VID:PID=0403:6011 SER=FT78U7W3C" | ||
print(f'vid: {device.vid}') # 1027 | print(f'vid: {device.vid}') # 1027 | ||
# 'description', 'device', 'hwid', 'interface', 'location', 'manufacturer', | # 'description', 'device', 'hwid', 'interface', 'location', 'manufacturer', | ||
# 'name', 'pid', 'product', 'serial_number', 'usb_description', 'usb_info', 'vid' | # 'name', 'pid', 'product', 'serial_number', 'usb_description', 'usb_info', 'vid' | ||
print('----') | print('----') | ||
</pre> | |||
--- | |||
== List FTDI Only == | |||
<pre> | |||
for device in serial.tools.list_ports.comports(): | |||
if device.manufacturer != "FTDI": | |||
continue | |||
print(device) # COM9 - USB Serial Port (COM9) | |||
print(f'description: {device.description}') # USB Serial Port (COM9) | |||
print(f'device: {device.device}') # COM9 | |||
print(f'hwid: {device.hwid}') # USB VID:PID=0403:6011 SER=FT78U7W3C | |||
print(f'manufacturer: {device.manufacturer}') # FTDI | |||
print(f'name: {device.name}') # COM9 | |||
print(f'pid: {device.pid}') # 24593 | |||
print(f'vid: {device.vid}') # 1027 | |||
print('----') | |||
</pre> | </pre> | ||
Latest revision as of 03:23, 27 August 2025
List Windows COM Ports
# https://stackoverflow.com/questions/12090503/listing-available-com-ports-with-python
import serial.tools.list_ports
for device in serial.tools.list_ports.comports():
#print(dir(device))
print(device) # COM9 - USB Serial Port (COM9)
print(f'description: {device.description}') # USB Serial Port (COM9)
print(f'device: {device.device}') # COM9
print(f'hwid: {device.hwid}') # USB VID:PID=0403:6011 SER=FT78U7W3C
print(f'interface: {device.interface}') # None
print(f'location: {device.location}') # None
print(f'manufacturer: {device.manufacturer}') # FTDI
print(f'name: {device.name}') # COM9
print(f'pid: {device.pid}') # 24593
print(f'product: {device.product}') # None
print(f'serial_number: {device.serial_number}') # FT78U7W3C
# print(f'usb_description: {device.usb_description}') # bound function - device.usb_description() - "COM9"
# print(f'usb_info: {device.usb_info}') # bound function - device.usb_info() - "USB VID:PID=0403:6011 SER=FT78U7W3C"
print(f'vid: {device.vid}') # 1027
# 'description', 'device', 'hwid', 'interface', 'location', 'manufacturer',
# 'name', 'pid', 'product', 'serial_number', 'usb_description', 'usb_info', 'vid'
print('----')
---
List FTDI Only
for device in serial.tools.list_ports.comports():
if device.manufacturer != "FTDI":
continue
print(device) # COM9 - USB Serial Port (COM9)
print(f'description: {device.description}') # USB Serial Port (COM9)
print(f'device: {device.device}') # COM9
print(f'hwid: {device.hwid}') # USB VID:PID=0403:6011 SER=FT78U7W3C
print(f'manufacturer: {device.manufacturer}') # FTDI
print(f'name: {device.name}') # COM9
print(f'pid: {device.pid}') # 24593
print(f'vid: {device.vid}') # 1027
print('----')