-
Notifications
You must be signed in to change notification settings - Fork 0
/
REVComPorts.py
48 lines (40 loc) · 1.25 KB
/
REVComPorts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from serial.tools import list_ports
import re
defaultComPort = 0
comPortCommand = ''
testFixture = False
class comPort:
def __init__(self, sn, name):
self.sn = sn
self.name = name
def getSN(self):
"""Get the serial number of a connected port"""
return self.sn
def getNumber(self):
"""Get the number for connected module (?)"""
num = re.findall('\\d+', self.name)
return num[-1]
def getName(self):
return self.name
def getPorts():
"""Get the USB comm ports (?)"""
comPorts = []
device_list = list_ports.comports()
for usbDevice in device_list:
if 'SER=' in usbDevice.hwid:
sections = usbDevice.hwid.split(' ')
for section in sections:
if 'SER=' in section:
serialNumber = section[4:]
deviceName = usbDevice.device
comPorts.append(comPort(serialNumber, deviceName))
return comPorts
def populateSerialPorts():
"""Populate available ports"""
global REVPorts
global serialPorts
serialPorts = getPorts()
REVPorts = []
for port in serialPorts:
if port.getSN().startswith('D') and len(port.getSN()) > 2:
REVPorts.append(port)