FTD2XX_NET.FTDI.GetDeviceList C# (CSharp) Method

GetDeviceList() public method

Gets information on all of the FTDI devices available.
Thrown when the supplied buffer is not large enough to contain the device info list.
public GetDeviceList ( FT_DEVICE_INFO_NODE devicelist ) : FT_STATUS
devicelist FT_DEVICE_INFO_NODE An array of type FT_DEVICE_INFO_NODE to contain the device information for all available devices.
return FT_STATUS
        public FT_STATUS GetDeviceList(FT_DEVICE_INFO_NODE[] devicelist)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
            FT_ERROR ftErrorCondition = FT_ERROR.FT_NO_ERROR;

            // If the DLL hasn't been loaded, just return here
            if (hFTD2XXDLL == IntPtr.Zero)
                return ftStatus;

            // Check for our required function pointers being set up
            if ((pFT_CreateDeviceInfoList != IntPtr.Zero) & (pFT_GetDeviceInfoDetail != IntPtr.Zero))
            {
                UInt32 devcount = 0;

                tFT_CreateDeviceInfoList FT_CreateDeviceInfoList = (tFT_CreateDeviceInfoList)Marshal.GetDelegateForFunctionPointer(pFT_CreateDeviceInfoList, typeof(tFT_CreateDeviceInfoList));
                tFT_GetDeviceInfoDetail FT_GetDeviceInfoDetail = (tFT_GetDeviceInfoDetail)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfoDetail, typeof(tFT_GetDeviceInfoDetail));

                // Call FT_CreateDeviceInfoList
                ftStatus = FT_CreateDeviceInfoList(ref devcount);

                // Allocate the required storage for our list

                byte[] sernum = new byte[16];
                byte[] desc = new byte[64];

                if (devcount > 0)
                {
                    // Check the size of the buffer passed in is big enough
                    if (devicelist.Length < devcount)
                    {
                        // Buffer not big enough
                        ftErrorCondition = FT_ERROR.FT_BUFFER_SIZE;
                        // Throw exception
                        ErrorHandler(ftStatus, ftErrorCondition);
                    }

                    // Instantiate the array elements as FT_DEVICE_INFO_NODE
                    for (UInt32 i = 0; i < devcount; i++)
                    {
                        devicelist[i] = new FT_DEVICE_INFO_NODE();
                        // Call FT_GetDeviceInfoDetail
                        ftStatus = FT_GetDeviceInfoDetail(i, ref devicelist[i].Flags, ref devicelist[i].Type, ref devicelist[i].ID, ref devicelist[i].LocId, sernum, desc, ref devicelist[i].ftHandle);
                        // Convert byte arrays to strings
                        devicelist[i].SerialNumber = Encoding.ASCII.GetString(sernum);
                        devicelist[i].Description = Encoding.ASCII.GetString(desc);
                        // Trim strings to first occurrence of a null terminator character
                        devicelist[i].SerialNumber = devicelist[i].SerialNumber.Substring(0, devicelist[i].SerialNumber.IndexOf("\0"));
                        devicelist[i].Description = devicelist[i].Description.Substring(0, devicelist[i].Description.IndexOf("\0"));
                    }
                }
            }
            else
            {
                if (pFT_CreateDeviceInfoList == IntPtr.Zero)
                {
                    LogB.Debug("FTD2XX: Failed to load function FT_CreateDeviceInfoList.");
                }
                if (pFT_GetDeviceInfoDetail == IntPtr.Zero)
                {
                    LogB.Debug("FTD2XX: Failed to load function FT_GetDeviceInfoListDetail.");
                }
            }
            return ftStatus;
        }

Usage Example

コード例 #1
1
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            FTD2XX_NET.FTDI dev = new FTDI();
            UInt32 numDevices = 0;
            dev.GetNumberOfDevices(ref numDevices);

            var pDest = new FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[numDevices];
            dev.GetDeviceList(pDest);

            VIDPIDList = string.Empty;
            for (int i = 0; i < numDevices; i++ )
            {
                VIDPIDList += string.Format("{0} \n", pDest[i].ID);
            }
        }
All Usage Examples Of FTD2XX_NET.FTDI::GetDeviceList