Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Scan for known serial ports available in the underling system.
Returns a tuple of tuples where each inner tuple contains the port
number and port name. For example:
.. sourcecode:: python
scan_ports()
((0, '/dev/ttyS0'), (1, '/dev/ttyS1'), ...)
"""
names = []
for number in range(256):
try:
# attempt attr `name` for PySerial >= 2.5-rc2,
# where attr `portstr` is for older PySerial versions
s = pyserial.Serial(number)
name = getattr(s, 'name', getattr(s, 'portstr', str(number)))
names.append((number, name,))
except:
pass
return tuple(names)
def get_databits():
"""
Returns supported byte sizes in a Django-like choices tuples.
"""
databits = []
s = pyserial.Serial()
for name, value in s.getSupportedByteSizes():
databits.append((value, name,))
return tuple(databits)
def get_baudrates():
"""
Returns supported baud rates in a Django-like choices tuples.
"""
baudrates = []
s = pyserial.Serial()
for name, value in s.getSupportedBaudrates():
baudrates.append((value, name,))
return tuple(baudrates)
def get_stopbits():
"""
Returns supported stop bit lengths in a Django-like choices tuples.
"""
stopbits = []
s = pyserial.Serial()
for name, value in s.getSupportedStopbits():
stopbits.append((value, name,))
return tuple(stopbits)