Browse Source

Tweaks and find_all added to SerialDevice.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
798af25586
2 changed files with 16 additions and 2 deletions
  1. +14
    -2
      pyad2usb/devices.py
  2. +2
    -0
      test.py

+ 14
- 2
pyad2usb/devices.py View File

@@ -3,6 +3,7 @@ import usb.util
import time import time
import threading import threading
import serial import serial
import serial.tools.list_ports
import traceback import traceback
from pyftdi.pyftdi.ftdi import * from pyftdi.pyftdi.ftdi import *
from pyftdi.pyftdi.usbtools import * from pyftdi.pyftdi.usbtools import *
@@ -39,7 +40,7 @@ class Device(object):
except util.CommError, err: except util.CommError, err:
self.stop() self.stop()


time.sleep(0.10)
time.sleep(0.01)


class USBDevice(Device): class USBDevice(Device):
FTDI_VENDOR_ID = 0x0403 FTDI_VENDOR_ID = 0x0403
@@ -152,10 +153,21 @@ class USBDevice(Device):
class SerialDevice(Device): class SerialDevice(Device):
BAUDRATE = 19200 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): def __init__(self):
Device.__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._read_thread = Device.ReadThread(self)
self._buffer = '' self._buffer = ''
self._running = False self._running = False


+ 2
- 0
test.py View File

@@ -37,6 +37,8 @@ try:
#overseer = pyad2usb.ad2usb.Overseer(attached_event=handle_attached, detached_event=handle_detached) #overseer = pyad2usb.ad2usb.Overseer(attached_event=handle_attached, detached_event=handle_detached)
#overseer.start() #overseer.start()


print pyad2usb.ad2usb.devices.SerialDevice.find_all()

#dev = pyad2usb.ad2usb.AD2USB() #dev = pyad2usb.ad2usb.AD2USB()
#dev = overseer.get_device() #dev = overseer.get_device()




Loading…
Cancel
Save