Created
May 25, 2018 11:42
-
-
Save jueti/1cda69baeb99ec130d98688b6f3999c2 to your computer and use it in GitHub Desktop.
Tool class to operate serial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from serial.tools.list_ports import comports | |
class SerialTools: | |
def __init__(self): | |
self.info = [] | |
def info(self): | |
pass | |
@staticmethod | |
def list_port(): | |
port_list = [{'description': i.description, 'vid': str(i.vid), 'pid': str(i.pid)} for i in comports()] | |
formatted_output = json.dumps(port_list, sort_keys=True, indent=4, separators=(',', ':')) | |
return formatted_output | |
if __name__ == '__main__': | |
print(SerialTools.list_port()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment