Skip to content

Instantly share code, notes, and snippets.

@michalmonday
Last active January 24, 2023 11:09
Show Gist options
  • Save michalmonday/68a96e924e236d924e0377038ccb8874 to your computer and use it in GitHub Desktop.
Save michalmonday/68a96e924e236d924e0377038ccb8874 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
'''
This script can be replaced by simply using:
python3 -m serial.tools.list_ports -v
'''
import serial # pip install pyserial
import serial.tools.list_ports as list_ports
import time
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'-v',
'--verbose',
required = False,
action = 'store_true',
help = "Prints all values for each port."
)
args = parser.parse_args()
print('All ports:')
for i, p in enumerate(list_ports.comports()):
print(f'{i+1}. device={p.device} name={p.name} description={p.description} manufacturer={p.manufacturer}')
if args.verbose:
for k,v in vars(p).items():
print(' ',k,v)
if args.verbose:
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment