def DemoOpenDeviceBy():

    if sys.platform == 'linux':
        DemoTurnOffPipeThreads()

    # get description and serial number of device at index 0
    ftd3xx.createDeviceInfoList()
    DEVICELIST = ftd3xx.getDeviceInfoList()

    # open device by index
    openby = 0
    logging.debug("Open by index [%d]" % openby)
    D3XX = ftd3xx.create(0, _ft.FT_OPEN_BY_INDEX)
    if (D3XX is None):
        logging.debug(
            "ERROR: Please check if another D3XX application is open!")
        return False
    D3XX.close()
    D3XX = 0

    # open device by description
    if sys.platform == 'linux':
        DemoTurnOffPipeThreads()
        ftd3xx.createDeviceInfoList()
        DEVICELIST = ftd3xx.getDeviceInfoList()
    openby = DEVICELIST[0].Description
    logging.debug("Open by description [%s]" % openby.decode('utf-8'))
    D3XX = ftd3xx.create(openby, _ft.FT_OPEN_BY_DESCRIPTION)
    if D3XX is None:
        logging.debug(
            "ERROR: Please check if another D3XX application is open!")
        return False
    D3XX.close()
    D3XX = 0

    # open device by serial number
    if sys.platform == 'linux':
        DemoTurnOffPipeThreads()
        ftd3xx.createDeviceInfoList()
        DEVICELIST = ftd3xx.getDeviceInfoList()
    openby = DEVICELIST[0].SerialNumber
    logging.debug("Open by serial number [%s]" % openby.decode('utf-8'))
    D3XX = ftd3xx.create(openby, _ft.FT_OPEN_BY_SERIAL_NUMBER)
    if D3XX is None:
        logging.debug(
            "ERROR: Please check if another D3XX application is open!")
        return False
    D3XX.close()
    D3XX = 0

    return True
Example #2
0
def FT_init() -> ftd3xx.FTD3XX:
    numDevices = ftd3xx.createDeviceInfoList()
    if numDevices == 0:
        print("no dev")
    else:
        devList = ftd3xx.getDeviceInfoList()
        devIndex = 0
        for i in range(numDevices):
            if devList[i].ID == 0x403601f:
                devIndex = i
            else:
                print("not find our dev")
                sys.exit()

        D3XX = ftd3xx.create(devIndex, _ft.FT_OPEN_BY_INDEX)
        devDesc = D3XX.getDeviceDescriptor()
        bUSB3 = devDesc.bcdUSB >= 0x300
        if (bUSB3 == False):
            print(
                "Warning: Device is connected using USB2 cable or through USB2 host controller!"
            )
        cfg = D3XX.getChipConfiguration()

        channelConfig = [
            "4 Channels", "2 Channels", "1 Channel", "1 OUT Pipe", "1 IN Pipe"
        ]
        print("\tChannelConfig = %#04x (%s)" %
              (cfg.ChannelConfig, channelConfig[cfg.ChannelConfig]))

        return D3XX
Example #3
0
def SetChipConfiguration(cfg=None, bDisplay=False):

    if sys.platform == 'linux':
        TurnOffPipeThreads()
        ftd3xx.createDeviceInfoList()
        ftd3xx.getDeviceInfoList()

    D3XX = ftd3xx.create(0, _ft.FT_OPEN_BY_INDEX)
    if D3XX is None:
        logging.debug(
            "ERROR: Please check if another D3XX application is open!")
        return False

    if bDisplay == True and cfg != None:
        DisplayChipConfiguration(cfg)
    D3XX.setChipConfiguration(cfg)

    D3XX.close()
    D3XX = 0

    WaitForDeviceReenumeration()
    return True
Example #4
0
def GetChipConfiguration(bDisplay=True):

    if sys.platform == 'linux':
        TurnOffPipeThreads()
        ftd3xx.createDeviceInfoList()
        ftd3xx.getDeviceInfoList()

    D3XX = ftd3xx.create(0, _ft.FT_OPEN_BY_INDEX)
    if D3XX is None:
        logging.debug(
            "ERROR: Please check if another D3XX application is open!")
        return None

    # get and display current chip configuration
    cfg = D3XX.getChipConfiguration()
    if bDisplay == True and cfg != None:
        DisplayChipConfiguration(cfg)

    D3XX.close()
    D3XX = 0

    return cfg
Example #5
0
    def __init__(self):
        try:
            import ftd3xx
            import sys
            if sys.platform == 'win32':
                import ftd3xx._ftd3xx_win32 as _ft
            elif sys.platform == 'linux2':
                import ftd3xx._ftd3xx_linux as _ft
        except:
            raise RuntimeError("ERROR: FTD3XX from FTDIchip.com is required")
            raise RuntimeError(
                "ERROR: Unable to import serial\n" +
                "PySerial from sourceforge.net is required for Serial Port access."
            )
        try:
            # check connected devices
            numDevices = ftd3xx.createDeviceInfoList()
            if (numDevices == 0):
                print("ERROR: No FTD3XX device is detected.")
                return False
            devList = ftd3xx.getDeviceInfoList()

            # Just open the first device (index 0)
            devIndex = 0
            self.D3XX = ftd3xx.create(devIndex, _ft.FT_OPEN_BY_INDEX)
            if (self.D3XX is None):
                print(
                    "ERROR: Please check if another D3XX application is open!")
                return False

            # check if USB3 or USB2
            devDesc = self.D3XX.getDeviceDescriptor()
            bUSB3 = devDesc.bcdUSB >= 0x300

            # validate chip configuration
            cfg = self.D3XX.getChipConfiguration()

        # process loopback for all channels
        except:
            raise RuntimeError("ERROR: Unable to open USB Port ")
        return
def DemoEnumerateDevices():

    numDevices = ftd3xx.createDeviceInfoList()
    if (numDevices == 0):
        return False

    # list devices by listDevices(description)
    logging.debug("List devices by listDevices(description)")
    DEVICES = ftd3xx.listDevices(_ft.FT_OPEN_BY_DESCRIPTION)
    if (DEVICES is None):
        return False
    logging.debug("Device count = %d" % len(DEVICES))
    for i in range(len(DEVICES)):
        logging.debug("DEVICE[%d] = %s" % (i, DEVICES[i].decode('utf-8')))
    DEVICES = 0
    logging.debug("")

    # list devices by listDevices(serial number)
    logging.debug("List devices by listDevices(serial number)")
    DEVICES = ftd3xx.listDevices(_ft.FT_OPEN_BY_SERIAL_NUMBER)
    if (DEVICES is None):
        return False
    logging.debug("Device count = %d" % len(DEVICES))
    for i in range(len(DEVICES)):
        logging.debug("DEVICE[%d] = %s" % (i, DEVICES[i].decode('utf-8')))
    DEVICES = 0
    logging.debug("")

    # list devices by getDeviceInfoList()
    logging.debug("List devices by getDeviceInfoList()")
    logging.debug("Device count = %d" % numDevices)
    DEVICELIST = ftd3xx.getDeviceInfoList()
    for i in range(numDevices):
        logging.debug("DEVICE[%d]" % i)
        logging.debug("\tFlags = %d" % DEVICELIST[i].Flags)
        logging.debug("\tType = %d" % DEVICELIST[i].Type)
        logging.debug("\tID = %#010X" % DEVICELIST[i].ID)
        logging.debug("\tLocId = %d" % DEVICELIST[i].LocId)
        logging.debug("\tSerialNumber = %s" %
                      DEVICELIST[i].SerialNumber.decode('utf-8'))
        logging.debug("\tDescription = %s" %
                      DEVICELIST[i].Description.decode('utf-8'))
    DEVICELIST = 0
    logging.debug("")

    # list devices by getDeviceInfoDetail()
    logging.debug("List devices by getDeviceInfoDetail()")
    logging.debug("Device count = %d" % numDevices)
    for i in range(numDevices):
        DEVICE = ftd3xx.getDeviceInfoDetail(i)
        logging.debug("DEVICE[%d]" % i)
        logging.debug("\tFlags = %d" % DEVICE['Flags'])
        logging.debug("\tType = %d" % DEVICE['Type'])
        logging.debug("\tID = %#010X" % DEVICE['ID'])
        logging.debug("\tLocId = %d" % DEVICE['LocId'])
        logging.debug("\tSerialNumber = %s" %
                      DEVICE['SerialNumber'].decode('utf-8'))
        logging.debug("\tDescription = %s" %
                      DEVICE['Description'].decode('utf-8'))
        DEVICE = 0
    logging.debug("")

    return True
Example #7
0
def main(channelsToTest=[0],
         transferSize=0,
         transferIteration=16,
         bWrite=False,
         bRead=True,
         bStressTest=False):

    logging.debug(
        "INPUT: CHANNELS=%s, SIZE=%d, ITERATION=%d, WRITE=%s, READ=%s, STRESS=%s"
        % (channelsToTest, transferSize, transferIteration, bWrite, bRead,
           bStressTest))
    logging.debug("")
    logging.debug("")

    # raise exception on error
    # ftd3xx.raiseExceptionOnError(True)

    if sys.platform == 'linux':
        DemoTurnOffPipeThreads()

    # check connected devices
    numDevices = ftd3xx.createDeviceInfoList()
    if (numDevices == 0):
        logging.debug(
            "ERROR: Please check environment setup! No device is detected.")
        return False
    logging.debug("Detected %d device(s) connected." % numDevices)
    devList = ftd3xx.getDeviceInfoList()
    DisplayDeviceList(numDevices, devList)
    devIndex = SelectDevice(numDevices)

    # open the first device (index 0)
    D3XX = ftd3xx.create(devIndex, _ft.FT_OPEN_BY_INDEX)
    if (D3XX is None):
        logging.debug(
            "ERROR: Please check if another D3XX application is open!")
        return False

    # get the version numbers of driver and firmware
    DisplayVersions(D3XX)
    if (sys.platform == 'win32' and D3XX.getDriverVersion() < 0x01020006):
        logging.debug(
            "ERROR: Old kernel driver version. Please update driver from Windows Update or FTDI website!"
        )
        D3XX.close()
        return False

    # check if USB3 or USB2
    devDesc = D3XX.getDeviceDescriptor()
    bUSB3 = devDesc.bcdUSB >= 0x300
    if (bUSB3 == False and transferSize == 16 * 1024 * 1024):
        transferSize = 4 * 1024 * 1024
    if (bUSB3 == False):
        logging.debug(
            "Warning: Device is connected using USB2 cable or through USB2 host controller!"
        )

    # validate chip configuration
    cfg = D3XX.getChipConfiguration()
    DisplayChipConfiguration(cfg)
    numChannels = [4, 2, 1, 0, 0]
    numChannels = numChannels[cfg.ChannelConfig]
    if (numChannels == 0):
        numChannels = 1
        if (cfg.ChannelConfig == _ft.FT_CONFIGURATION_CHANNEL_CONFIG_1_OUTPIPE
            ):
            bWrite = True
            bRead = False
        elif (cfg.ChannelConfig == _ft.FT_CONFIGURATION_CHANNEL_CONFIG_1_INPIPE
              ):
            bWrite = False
            bRead = True
    if (cfg.OptionalFeatureSupport & _ft.
            FT_CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCHALL
        ):
        logging.debug(
            "invalid chip configuration: notification callback is set")
        D3XX.close()
        return False

    # delete invalid channels
    for channel in range(len(channelsToTest) - 1, -1, -1):
        if (channelsToTest[channel] >= numChannels):
            del channelsToTest[channel]
    if (len(channelsToTest) == 0):
        D3XX.close()
        return

    # process loopback for all channels
    error = ProcessStreaming(D3XX, channelsToTest, transferSize,
                             transferIteration, bWrite, bRead, bStressTest)
    if error:
        DisplayTroubleshootingGuide("STREAMER", devList, devIndex, cfg)

    D3XX.close()
    D3XX = 0

    return True