How to use the pyftdi.pyftdi.ftdi.Ftdi function in pyftdi

To help you get started, we’ve selected a few pyftdi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nutechsoftware / alarmdecoder / test / test_devices.py View on Github external
def test_find_default_param(self):
        with patch.object(Ftdi, 'find_all', return_value=[(0, 0, 'AD2', 1, 'AD2')]):
            device = USBDevice.find()

            self.assertEqual(device.interface, 'AD2')
github nutechsoftware / alarmdecoder / test / test_devices.py View on Github external
def test_find_all_exception(self):
            with patch.object(Ftdi, 'find_all', side_effect=[USBError('testing'), FtdiError]) as mock:
                with self.assertRaises(CommError):
                    devices = USBDevice.find_all()

                with self.assertRaises(CommError):
                    devices = USBDevice.find_all()
github nutechsoftware / alarmdecoder / test / test_devices.py View on Github external
def test_find_with_param(self):
            with patch.object(Ftdi, 'find_all', return_value=[(0, 0, 'AD2-1', 1, 'AD2'), (0, 0, 'AD2-2', 1, 'AD2')]):
                device = USBDevice.find((0, 0, 'AD2-1', 1, 'AD2'))
                self.assertEquals(device.interface, 'AD2-1')

                device = USBDevice.find((0, 0, 'AD2-2', 1, 'AD2'))
                self.assertEquals(device.interface, 'AD2-2')
github nutechsoftware / alarmdecoder / alarmdecoder / devices.py View on Github external
def __init__(self, interface=0, vid=None, pid=None):
        """
        Constructor

        :param interface: May specify either the serial number or the device
                          index.
        :type interface: string or int
        """
        if not have_pyftdi:
            raise ImportError('The USBDevice class has been disabled due to missing requirement: pyftdi or pyusb.')

        Device.__init__(self)

        self._device = Ftdi()

        self._interface = 0
        self._device_number = 0
        self._serial_number = None

        self._vendor_id = USBDevice.DEFAULT_VENDOR_ID
        if vid:
            self._vendor_id = vid

        self._product_id = USBDevice.DEFAULT_PRODUCT_ID
        if pid:
            self._product_id = pid

        self._endpoint = 0
        self._description = None
github CospanDesign / nysa / nysa / host / userland / python / dionysus / fifo / fifo.py View on Github external
def __init__(self, vendor, product):
        self.vendor = vendor
        self.product = product
        self.f = Ftdi()
github CospanDesign / nysa / nysa / host / userland / python / dionysus / bitbang / bitbang.py View on Github external
def __init__(self, vendor_id, product_id, interface, debug = False):
        self.vendor = vendor_id
        self.product = product_id
        self.interface = interface
        self.f = Ftdi()
        self.debug = True
        self.f.open_bitbang(vendor_id, product_id, interface)
github CospanDesign / nysa / nysa / host / userland / python / dionysus / dionysus.py View on Github external
def __init__(self, idVendor = 0x0403, idProduct = 0x8530, sernum = None, debug = False):
        Nysa.__init__(self, debug)
        self.vendor = idVendor
        self.product = idProduct
        self.sernum = sernum

        self.debug = debug
        self.dev = None
        self.lock = threading.Lock()
        

        self.dev = Ftdi()
        self._open_dev()
        self.name = "Dionysus"
        self.debug = debug
        try:
            #XXX: Hack to fix a strange bug where FTDI
            #XXX: won't recognize Dionysus until a read and reset occurs
            btimeout = self.timeout
            self.timeout = 0.1
            self.ping()
            self.timeout = btimeout
        except NysaCommError:
            self.timeout = btimeout

        self.reset()

        self.interrupts = 0x00
github CospanDesign / nysa / nysa / host / userland / python / dionysus / fifo / fifo.py View on Github external
def set_sync_fifo(self, frequency = 30.0E6, latency = 2):
        """Configure the interface for synchronous FIFO mode"""
        self.f.add_type(self.vendor, self.product, 0x700, "ft2232h")
        self.f.open(self.vendor, self.product, 0)
        #Drain the input buffer
        self.f.purge_buffers()
        #Enable MPSSE Mode
        self.f.set_bitmode(0x00, Ftdi.BITMODE_SYNCFF)
        #Configure the clock
        frequency = self.f._set_frequency(frequency)
        #Set latency timer
        self.f.set_latency_timer(latency)

        #Set Chunk size
        self.f.write_data_set_chunksize(0x10000)
        self.f.read_data_set_chunksize(0x10000)

        self.f.set_flowctrl('hw')
        self.f.purge_buffers()
        return frequency
github CospanDesign / nysa / nysa / host / userland / python / dionysus / dionysus-control.py View on Github external
Raises:
            Exception
        """
        self.dev = Ftdi()
        frequency = 30.0E6
        latency  = 4
        Ftdi.add_type(self.vendor, self.product, 0x700, "ft2232h")
        self.dev.open(self.vendor, self.product, 0)

        #Drain the input buffer
        self.dev.purge_buffers()

        #Reset
        #Enable MPSSE Mode
        self.dev.set_bitmode(0x00, Ftdi.BITMODE_SYNCFF)


        #Configure Clock
        frequency = self.dev._set_frequency(frequency)

        #Set Latency Timer
        self.dev.set_latency_timer(latency)

        #Set Chunk Size
        self.dev.write_data_set_chunksize(0x10000)
        self.dev.read_data_set_chunksize(0x10000)

        #Set the hardware flow control
        self.dev.set_flowctrl('hw')
        self.dev.purge_buffers()
github nutechsoftware / alarmdecoder / alarmdecoder / devices.py View on Github external
Returns all FTDI devices matching our vendor and product IDs.

        :returns: list of devices
        :raises: :py:class:`~alarmdecoder.util.CommError`
        """
        if not have_pyftdi:
            raise ImportError('The USBDevice class has been disabled due to missing requirement: pyftdi or pyusb.')

        cls.__devices = []

        query = cls.PRODUCT_IDS
        if vid and pid:
            query = [(vid, pid)]

        try:
            cls.__devices = Ftdi.find_all(query, nocache=True)

        except (usb.core.USBError, FtdiError) as err:
            raise CommError('Error enumerating AD2USB devices: {0}'.format(str(err)), err)

        return cls.__devices