Example #1
0
 def test_close_on_disconnect(self):
     """Validate close after disconnect."""
     log = logging.getLogger('pyftdi.tests.ftdi')
     url = environ.get('FTDI_DEVICE', 'ftdi:///1')
     ftdi = Ftdi()
     ftdi.open_from_url(url)
     self.assertTrue(ftdi.is_connected, 'Unable to connect to FTDI')
     print('Please disconnect FTDI device')
     while ftdi.is_connected:
         try:
             ftdi.poll_modem_status()
         except FtdiError:
             break
         sleep(0.1)
     ftdi.close()
     print('Please reconnect FTDI device')
     while True:
         UsbTools.flush_cache()
         try:
             ftdi.open_from_url(url)
         except (FtdiError, UsbToolsError):
             log.debug('FTDI device not detected')
             sleep(0.1)
         except ValueError:
             log.warning('FTDI device not initialized')
             ftdi.close()
             sleep(0.1)
         else:
             log.info('FTDI device detected')
             break
     ftdi.poll_modem_status()
     ftdi.close()
Example #2
0
 def test_multiple_interface(self):
     # the following calls used to create issues (several interfaces from
     # the same device). The test expects an FTDI 2232H here
     ftdi1 = Ftdi()
     ftdi1.open(vendor=0x403, product=0x6010, interface=1)
     ftdi2 = Ftdi()
     ftdi2.open(vendor=0x403, product=0x6010, interface=2)
     for _ in range(5):
         print("If#1: ", hex(ftdi1.poll_modem_status()))
         print("If#2: ", ftdi2.modem_status())
         sleep(0.500)
     ftdi1.close()
     ftdi2.close()
Example #3
0
 def test_multiple_interface(self):
     # the following calls used to create issues (several interfaces from
     # the same device). The test expect an FTDI 2232H here
     ftdi1 = Ftdi()
     ftdi1.open(vendor=0x403, product=0x6014, interface=1)
     # ftdi2 = Ftdi()
     # ftdi2.open(vendor=0x403, product=0x6014, interface=2)
     import time
     for x in range(5):
         print "poll_modem_status: ", hex(ftdi1.poll_modem_status())
         # print "modem_status: ", ftdi1.modem_status()
         # print "If#2: ", ftdi2.modem_status()
         time.sleep(0.500)
     ftdi1.close()
Example #4
0
 def test_multiple_interface(self):
     # the following calls used to create issues (several interfaces from
     # the same device)
     ftdi1 = Ftdi()
     ftdi1.open(interface=1)
     ftdi2 = Ftdi()
     ftdi2.open(interface=2)
     import time
     for x in range(5):
         print "If#1: ", hex(ftdi1.poll_modem_status())
         print "If#2: ", ftdi2.modem_status()
         time.sleep(0.500)
     ftdi1.close()
     ftdi2.close()
Example #5
0
    ft.purge_tx_buffer()
    ft.purge_rx_buffer()
    ft.set_break(False)
    #ft.set_flowctrl()
    ft.read_data_bytes(5).tolist()

    fifo_wr = []
    for i in range(N):
        aux = (i + 1) % 256
        aux = randint(0, 255)
        fifo_wr.append(aux)
        print("______________")
        print("CTS? {}\tDSR? {}\tRI? {}".format(ft.get_cts(), ft.get_dsr(),
                                                ft.get_ri()))
        print("Poll Modem status? {}\tModem Status? {}".format(
            ft.poll_modem_status(), ft.modem_status()))
        print("______________")
        print("\twrite: " + str(ft.write_data(bytes([aux]))), aux)
        time.sleep(0.01)
        aux = ft.read_data_bytes(5).tolist()
        if (len(aux) > 0):
            print("\tread = {}".format(aux))
            fifo_rd = fifo_rd + aux
        else:
            print("\t...")

    print("\n... Reading more...")
    while True:
        time.sleep(2)
        aux = ft.read_data_bytes(1).tolist()
        if (len(aux) == 0): break
Example #6
0
from pyftdi.ftdi import Ftdi
from time import sleep

ftdi1 = Ftdi()
ftdi1.open(vendor=0x403, product=0x6015, interface=1)

vps = [(0x0403, 0x6015)]

for x in range(5):
    print("If#1: ", hex(ftdi1.poll_modem_status()))
    print("Read Pins:", bin(ftdi1.read_pins()))
    print("Devices:", bin(ftdi1.find_all(vps)))
    sleep(0.500)

ftdi1.close()