Browse Source

Added support for using grep to search for serial devices.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
bb8e57cf8d
2 changed files with 12 additions and 3 deletions
  1. +5
    -2
      pyad2usb/devices.py
  2. +7
    -1
      test.py

+ 5
- 2
pyad2usb/devices.py View File

@@ -249,14 +249,17 @@ class SerialDevice(Device):
BAUDRATE = 19200

@staticmethod
def find_all():
def find_all(pattern=None):
"""
Returns all serial ports present.
"""
devices = []

try:
devices = serial.tools.list_ports.comports()
if pattern:
devices = serial.tools.list_ports.grep(pattern)
else:
devices = serial.tools.list_ports.comports()
except Exception, err:
raise util.CommError('Error enumerating AD2SERIAL devices: {0}'.format(str(err)))



+ 7
- 1
test.py View File

@@ -226,6 +226,11 @@ def test_no_read_thread():

a2u.close()

def test_serial_grep():
re = pyad2usb.devices.SerialDevice.find_all(pattern='VID:PID=067b:2303')
for x in re:
print x

try:
signal.signal(signal.SIGINT, signal_handler)

@@ -236,13 +241,14 @@ try:
#test_usb_serial()
#test_factory()
#test_factory_watcher()
upload_usb()
#upload_usb()
#upload_usb_serial()

#test_socket()
#upload_socket()

#test_no_read_thread()
test_serial_grep()

except Exception, err:
traceback.print_exc(err)

Loading…
Cancel
Save