Browse Source

Working towards making AD2USB usable again. Wired the intermediate event chain together.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
7b31015a3a
3 changed files with 55 additions and 13 deletions
  1. +26
    -6
      pyad2usb/ad2usb.py
  2. +14
    -0
      pyad2usb/devices.py
  3. +15
    -7
      test.py

+ 26
- 6
pyad2usb/ad2usb.py View File

@@ -109,16 +109,36 @@ class AD2USB(object):
def __del__(self):
pass

def open(self):
def open(self, baudrate=None, interface=None, index=None):
self._wire_events()
self._device.open()
self._device.open(baudrate=baudrate, interface=interface, index=index)

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

def _wire_events(self):
self._device.on_open += self.on_open
self._device.on_close += self.on_close
self._device.on_read += self.on_read
self._device.on_write += self.on_write
self._device.on_open += self._on_open
self._device.on_close += self._on_close
self._device.on_read += self._on_read
self._device.on_write += self._on_write

def _on_open(self, sender, args):
print '_on_open: {0}'.format(args)

self.on_open(args)

def _on_close(self, sender, args):
print '_on_close: {0}'.format(args)

self.on_close(args)

def _on_read(self, sender, args):
print '_on_read: {0}'.format(args)

self.on_read(args)

def _on_write(self, sender, args):
print '_on_write: {0}'.format(args)

self.on_write(args)

+ 14
- 0
pyad2usb/devices.py View File

@@ -74,6 +74,13 @@ class USBDevice(Device):
def open(self, baudrate=BAUDRATE, interface=0, index=0):
self._running = True

if baudrate is None:
baudrate = BAUDRATE
if interface is None:
interface = 0
if index is None:
index = 0

try:
self._device.open(self._vendor_id,
self._product_id,
@@ -176,6 +183,13 @@ class SerialDevice(Device):
pass

def open(self, baudrate=BAUDRATE, interface=0, index=0):
if baudrate is None:
baudrate = BAUDRATE
if interface is None:
interface = 0
if index is None:
index = 0

self._device.baudrate = baudrate
self._device.port = interface



+ 15
- 7
test.py View File

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

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

#dev = pyad2usb.ad2usb.AD2USB()
#dev = overseer.get_device()
@@ -45,18 +45,26 @@ try:
#dev = pyad2usb.ad2usb.Overseer.create()
dev = pyad2usb.ad2usb.devices.SerialDevice()
#dev = pyad2usb.ad2usb.devices.USBDevice()#serial='A101A429', description='FT232R USB UART')
dev.on_open += handle_open
dev.on_close += handle_close
dev.on_read += handle_read
dev.on_write += handle_write
#dev.on_open += handle_open
#dev.on_close += handle_close
#dev.on_read += handle_read
#dev.on_write += handle_write

a2u = pyad2usb.ad2usb.AD2USB(dev)
a2u.on_open += handle_open
a2u.on_close += handle_close
a2u.on_read += handle_read
a2u.on_write += handle_write
a2u.open(baudrate=19200, interface='/dev/ttyUSB0')
#dev.open(baudrate=115200, interface='/dev/ttyUSB5')
dev.open(baudrate=19200, interface='/dev/ttyUSB0')
#dev.open(baudrate=19200, interface='/dev/ttyUSB0')
#dev.open()

while running:
time.sleep(0.1)

dev.close()
a2u.close()
#dev.close()
#overseer.close()

#wut.close()


Loading…
Cancel
Save