/// <summary> /// populate an FTDI list of all FTDI devices found /// create aaDevices list of devices /// for each ftdi device update device fields: /// create new device /// device ID /// device serial number (our unique number) /// device prod description (Flat Fielder for our products) /// add this device to the aadevices list /// </summary> /// <returns>FT_STATUS_OK or error</returns> public FTDI.FT_STATUS popFTDevList() { FTDI.FT_STATUS ftStat = FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND; // Allocate storage for device info list if (ftdiDeviceCount > 0) { // Populate device list ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; ftStat = FtDevice.GetDeviceList(ftdiDeviceList); if (ftStat != FTDI.FT_STATUS.FT_OK) return ftStat; //create aalist and fill in ftdi and windows info aaDevices = new List<device>(); foreach (FTDI.FT_DEVICE_INFO_NODE ft in ftdiDeviceList) { //create new device device d = new device(); //update device info from fdti // dev ID, serial num, description d.DevID = ft.ID.ToString(); d.ProdSerialNumber = ft.SerialNumber; d.ProdDescr = ft.Description; //add device to AaDevices list aaDevices.Add(d); } } return ftStat; }
/// <summary> /// Index through list AaDevices /// open each by serial number /// get comport put in list /// if prod descr is "Flat Fielder", or ping is true /// send ping get AA prodID number put in list /// resolve AA prodID name from prodID number, put in list /// else delete device from aaDevices list /// close device /// </summary> /// <returns></returns> public FTDI.FT_STATUS popAADevListUsing(bool ping) { string comPort = string.Empty; device d = new device(); List<device> tempList = new List<device>(); int aaIndex = 0; FTDI.FT_STATUS ftStat = FTDI.FT_STATUS.FT_OK; //updtate these to fix problem of finding devices immediately after //plugging something in ftStat = getNumFTDevices(); if (ftStat != FTDI.FT_STATUS.FT_OK) return ftStat; ftStat = popFTDevList(); if (ftStat != FTDI.FT_STATUS.FT_OK) return ftStat; if (AaDevices != null) { for (int index = 0; index < AaDevices.Count; index++) { d = AaDevices[index]; //PING USING SERIAL NUMBER AND CHECK FOR PROD ID if (d.ProdDescr == AA_PROD_DESC | (ping && (d.ProdDescr == FT_PROD_DESC))) { try { ftStat = FtDevice.OpenBySerialNumber(d.ProdSerialNumber); if (ftStat != FTDI.FT_STATUS.FT_OK) continue; ftStat = FtDevice.GetCOMPort(out comPort); if (ftStat != FTDI.FT_STATUS.FT_OK) continue; d.ComPort = comPort; Thread.Sleep(100); //was 2000 //ftStat = FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND; if (isFFHere()) { d.AAProdIDNum = prodIDNum; d.DevIndex = aaIndex++; //convert prodID to prodName d.AAProdIDName = ((ProductArray)int.Parse(d.AAProdIDNum)).ToString(); tempList.Add(d); } } catch (Exception ex) { throw ex; } FtDevice.Close(); } //end if }//end for AaDevices.Clear(); AaDevices = tempList; } //end if if (AaDevices.Count == 0) ftStat = FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND; return ftStat; }