I have a c# windows form program which uses the FTDI FTD2XX_NET library to enumerate devices using the ftdi driver and get their comports.
My problem is I want to determine specifically if the hardware I am talking to is the specific device I am looking for. This is a custom piece of hardware, but it looks like the vendor left the generic PID/VID for the FTDI chipset.
Right now I have resorted to sending a command and waiting for a valid response/timeout but this seems likely to fail in the greater world given the large number of devices using this chipset.
What is the correct approach to tackle this? I am not a hardware programmer so I am not sure what the best practice recommendation for this would be. I can ask the vendor to modify the hardware- firmware if needed.
Even with a generic PID/VID, the vendor can change the device description, so you can check it before starting the communication:
// Create new instance of the FTDI device class
var ftdiDevice = new FTDI();
// Check how many FTDI devices are connected
uint deviceNum = 0;
ftdiDevice.GetNumberOfDevices(ref deviceNum);
var status = FTDI.FT_STATUS.FT_DEVICE_NOT_FOUND;
if (deviceNum > 0)
{
// Get information about the connected devices
var devicelist = new FTDI.FT_DEVICE_INFO_NODE[deviceNum];
ftdiDevice.GetDeviceList(devicelist);
for (uint i = 0; i < deviceNum; i++)
{
if (devicelist[i].Description == "My Device Description")
{
status = ftdiDevice.OpenByIndex(i);
break;
}
}
}
if (status != FTDI.FT_STATUS.FT_OK)
{
throw new Exception("Unable to connect");
}
You can check or change the device description, serial number, PID/VID, etc. using FT PROG. Using a custom description while leaving the generic PID/VID will allow you to use the signed drivers from FTDI without any modification.