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;
}