def open_comms(self):
     self.ftdic = ftdi.new()
     ret = ftdi.usb_open(self.ftdic, self.idVendor, self.idProduct)
     print ret
     ret = ftdi.usb_purge_buffers(self.ftdic)
     print ret
     ret = ftdi.set_bitmode(self.ftdic, 0xFF, ftdi.BITMODE_BITBANG)
     print ret
Пример #2
0
 def purge(self):
     """Purge all FTDI buffers."""
     if self.ftdic is not None:
         ftdi.usb_purge_buffers(self.ftdic)
Пример #3
0

# Initialize FTDI device connection.
ctx = ftdi.new()
ftdi.usb_open(ctx, 0x263d, 0x4001)
ftdi.usb_reset(ctx)

# Disable flow control. Commented out because it is unclear if this is necessary.
#self._check(ftdi.setflowctrl, ftdi.SIO_DISABLE_FLOW_CTRL)

# Change read & write buffers to maximum size, 65535 bytes.
ftdi.read_data_set_chunksize(ctx, 65535)
ftdi.write_data_set_chunksize(ctx, 65535)

# Clear pending read data & write buffers.
ftdi.usb_purge_buffers(ctx)
# Reset MPSSE
ftdi.set_bitmode(ctx, 0, 0)
# Enable MPSSE
ftdi.set_bitmode(ctx, 0, 2)


def ftwrite(string):
    length = len(string)
    ret = ftdi.write_data(ctx, string, length)
    if ret < 0:
        raise RuntimeError('ftdi_write_data failed with error {0}: {1}'.format(
            ret, ftdi.get_error_string(self._ctx)))
    if ret != length:
        raise RuntimeError(
            'ftdi_write_data expected to write {0} bytes but actually wrote {1}!'