예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
0
def DemoWaitForDeviceReenumeration():

    # should be called when setChipConfiguration, cycleDevicePort or resetDevicePort is called
    # todo: get optimal sleep times
    origValue = ftd3xx.raiseExceptionOnError(False)
    time.sleep(1)
    while (ftd3xx.listDevices() == None):
        time.sleep(1)
    time.sleep(1)
    ftd3xx.raiseExceptionOnError(origValue)

    if sys.platform == 'linux':
        count = 0
        while count == 0:
            count = ftd3xx.createDeviceInfoList()
예제 #5
0
    def run(self):
        # Reset readout system -------------------------------------------------------------------------------------------------
        self.serial_obj.execute_cmd("set_nrst 0")
        time.sleep(0.5)
        self.serial_obj.execute_cmd("set_nrst 1")
        time.sleep(0.5)

        # Power on chip --------------------------------------------------------------------------------------------------------
        self.serial_obj.execute_cmd("set_vdd2_en 1")
        time.sleep(0.5)
        self.serial_obj.execute_cmd("set_vdd1_en 1")
        self.serial_obj.execute_cmd("set_avdd_en 1")
        time.sleep(2)
        #self.serial_obj.execute_cmd("power_on")

        # FT601Q ---------------------------------------------------------------------------------------------------------------
        # - Check connected devices
        numDevices = ftd3xx.createDeviceInfoList()
        if (numDevices == 0):
            print("FT601 not connected !")
            return
        # - Open the first device (index 0)
        self.usb_obj = ftd3xx.create(0, _ft.FT_OPEN_BY_INDEX)
        self.usb_obj.setPipeTimeout(0x82, 0)
        # - Set stream pipe
        self.usb_obj.setStreamPipe(0x82, self.data_size)

        # Main Loop ------------------------------------------------------------------------------------------------------------
        # - init
        self.offset = np.zeros((128, 128))
        self.av_list = []
        self.px_list = []

        self.run = True
        while (self.run):
            data = self.usb_obj.readPipeEx(0x82, self.data_size, raw=True)
            print('%.16f' % time.time())
            num = data['bytesTransferred']
            data = data['bytes']
            #print(num, data[0], data[-1])
            threading.Thread(target=self.save_and_plot, args=(data, )).start()

        self.usb_obj.close()

        #self.serial_obj.execute_cmd("power_off")
        # ----------------------------------------------------------------------------------------------------------------------
        self.done_s.emit(self.file_path)
예제 #6
0
  def __init__ ( self, debug ):
    self.debug = debug;
    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");
    try:
      # check connected devices
      numDevices = ftd3xx.createDeviceInfoList()
      if (numDevices == 0):
        print("ERROR: No FTD3XX device is detected.");
        return False;
      # devList = ftd3xx.getDeviceInfoList();
      devIndex = 0; # Assume a single device and open first device
      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;

      # Reset the FT600 to make sure starting fresh with nothing in FIFOs
      self.D3XX.resetDevicePort(); # Flush
      self.D3XX.close();
      self.D3XX = ftd3xx.create(devIndex, _ft.FT_OPEN_BY_INDEX);

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

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

      # Timeout is in ms,0=Blocking. Defaults to 5,000
      rts = self.D3XX.setPipeTimeout( pipeid = 0xFF, timeoutMS = 1000 );

    # process loopback for all channels
    except:
      raise RuntimeError("ERROR: Unable to open USB Port " );
    return;
예제 #7
0
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
예제 #8
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
예제 #9
0
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
예제 #10
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