public GetDescription ( string &Description ) : FT_STATUS | ||
Description | string | The description of the current device. |
return | FT_STATUS |
public FT_STATUS GetDescription(out string Description)
{
// Initialise ftStatus to something other than FT_OK
FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;
Description = String.Empty;
// 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_GetDeviceInfo != IntPtr.Zero)
{
tFT_GetDeviceInfo FT_GetDeviceInfo = (tFT_GetDeviceInfo)Marshal.GetDelegateForFunctionPointer(pFT_GetDeviceInfo, typeof(tFT_GetDeviceInfo));
UInt32 DeviceID = 0;
FT_DEVICE DeviceType = FT_DEVICE.FT_DEVICE_UNKNOWN;
byte[] sernum = new byte[16];
byte[] desc = new byte[64];
if (ftHandle != IntPtr.Zero)
{
// Call FT_GetDeviceInfo
ftStatus = FT_GetDeviceInfo(ftHandle, ref DeviceType, ref DeviceID, sernum, desc, IntPtr.Zero);
Description = Encoding.ASCII.GetString(desc);
Description = Description.Substring(0, Description.IndexOf("\0"));
}
}
else
{
if (pFT_GetDeviceInfo == IntPtr.Zero)
{
LogB.Debug("FTD2XX: Failed to load function FT_GetDeviceInfo.");
}
}
return ftStatus;
}
/// <summary> /// Called when the window is loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WindowLoaded(object sender, RoutedEventArgs e) { int i; // Configure datagrid dataGrid1.Items.Clear(); dataGrid1.Columns.Clear(); dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Device Number", Binding = new Binding("Dn") }); dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Serial Number", Binding = new Binding("Sn") }); dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Device Description", Binding = new Binding("Dd") }); // Get FTDI basic data FTDI f = new FTDI(); uint devicecount = 0; f.GetNumberOfDevices(ref devicecount); // Fill datagrid with device data string dd, sn, dn; if (devicecount == 0) { FtErrorReport("GetFTDeviceCount", FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND); } for (i = 0; i < devicecount; i++) { f.OpenByIndex((uint)i); dn = String.Format("Device {0}", i); f.GetSerialNumber(out sn); f.GetDescription(out dd); f.Close(); dataGrid1.Items.Add( new SDevice{ Dd = dd, Dn = dn, Sn = sn } ); } }