from pylibftdi.driver import Device, FtdiError
+from ctypes import c_ubyte, byref
simple subclass to support bit-bang mode
- Only uses async mode at the moment.
+ Internally uses async mode at the moment, but provides a 'sync'
+ flag (defaulting to True) which controls the behaviour of port
+ reading and writing - if set, the FIFOs are ignored (read) or
+ cleared (write) so operations will appear synchronous
Adds two read/write properties to the base class:
direction: 8 bit input(0)/output(1) direction control.
# initialise the super-class, but don't open yet. We really want
# two-part initialisation here - set up all the instance variables
# here in the super class, then open it after having set more
self.direction = direction
self._last_set_dir = None
lines is persisted in this object for the purposes of reading,
so read-modify-write operations (e.g. drv.port+=1) are valid.
- # the coercion to bytearray here is to make this work
- # transparently between Python2 and Python3 - equivalent
- # of ord() for Python2, a time-wasting do-nothing on Python3
- result = bytearray(super(BitBangDevice, self).read(1))
+ res = self.fdll.ftdi_read_pins(self.ctx, byref(pin_byte))
+ raise FtdiError("Could not read device pins")
+ result = pin_byte.value
+ # the coercion to bytearray here is to make this work
+ # transparently between Python2 and Python3 - equivalent
+ # of ord() for Python2, a time-wasting do-nothing on Python3
+ result = bytearray(super(BitBangDevice, self).read(1))
# replace the 'output' bits with current value of _latch -
# the last written value. This makes read-modify-write
# operations (e.g. 'drv.port |= 0x10') work as expected
return super(BitBangDevice, self).write(chr(value))