Browse Source

buildbuildbuild

pyserial_fix
Scott Petersen 11 years ago
parent
commit
6602131b8f
1 changed files with 19 additions and 4 deletions
  1. +19
    -4
      pyad2usb/ad2usb.py

+ 19
- 4
pyad2usb/ad2usb.py View File

@@ -5,15 +5,30 @@ import usb.core
import usb.util import usb.util


class AD2USB(object): class AD2USB(object):
@classmethod
def find_all(cls):
cls.__devices = Device.find_all()

return cls.__devices

def __init__(self): def __init__(self):
self._device = None self._device = None


AD2USB.find_all()

def __del__(self): def __del__(self):
pass pass


def open(self, device=None): def open(self, device=None):
# If device is None, open first.
pass
if len(cls.__devices) == 0:
raise NoDeviceError

if device is None:
self._device = cls.__devices[0]
else
self._device = device

self._device.open()


def close(self): def close(self):
self._device.close() self._device.close()
@@ -24,7 +39,7 @@ class AD2USB(object):
class Device(object): class Device(object):
FTDI_VENDOR_ID = 0x0403 FTDI_VENDOR_ID = 0x0403
FTDI_PRODUCT_ID = 0x6001 FTDI_PRODUCT_ID = 0x6001
AD2USB_BAUDRATE = 115200
BAUDRATE = 115200


@staticmethod @staticmethod
def find_all(): def find_all():
@@ -45,7 +60,7 @@ class Device(object):
self._buffer = '' self._buffer = ''
self._device = Ftdi() self._device = Ftdi()


def open(self, baudrate=AD2USB_BAUDRATE, interface=0, index=0):
def open(self, baudrate=BAUDRATE, interface=0, index=0):
self._device.open(self._vendor_id, self._device.open(self._vendor_id,
self._product_id, self._product_id,
interface, interface,


Loading…
Cancel
Save