From 798af25586cc7ffb7d4bb6f9d65867a6439983c8 Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Tue, 14 May 2013 17:05:49 -0700 Subject: [PATCH] Tweaks and find_all added to SerialDevice. --- pyad2usb/devices.py | 16 ++++++++++++++-- test.py | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pyad2usb/devices.py b/pyad2usb/devices.py index 6ec0dd8..1ff7431 100644 --- a/pyad2usb/devices.py +++ b/pyad2usb/devices.py @@ -3,6 +3,7 @@ import usb.util import time import threading import serial +import serial.tools.list_ports import traceback from pyftdi.pyftdi.ftdi import * from pyftdi.pyftdi.usbtools import * @@ -39,7 +40,7 @@ class Device(object): except util.CommError, err: self.stop() - time.sleep(0.10) + time.sleep(0.01) class USBDevice(Device): FTDI_VENDOR_ID = 0x0403 @@ -152,10 +153,21 @@ class USBDevice(Device): class SerialDevice(Device): BAUDRATE = 19200 + @staticmethod + def find_all(): + devices = [] + + try: + devices = serial.tools.list_ports.comports() + except Exception, err: + raise util.CommError('Error enumerating AD2SERIAL devices: {0}'.format(str(err))) + + return devices + def __init__(self): Device.__init__(self) - self._device = serial.Serial(timeout=0) + self._device = serial.Serial(timeout=0) # Timeout = non-blocking to match pyftdi. self._read_thread = Device.ReadThread(self) self._buffer = '' self._running = False diff --git a/test.py b/test.py index f116a23..557cbd5 100755 --- a/test.py +++ b/test.py @@ -37,6 +37,8 @@ try: #overseer = pyad2usb.ad2usb.Overseer(attached_event=handle_attached, detached_event=handle_detached) #overseer.start() + print pyad2usb.ad2usb.devices.SerialDevice.find_all() + #dev = pyad2usb.ad2usb.AD2USB() #dev = overseer.get_device()