问题描述
我想检测连接的 USB 设备(FT232R USB UART,虚拟 com 端口驱动程序)。这通常工作正常,但由于 Windows 更新,我的设备被检测为 FTDI_DEVICE_UNKNOWN。奇怪的行为是,当我第一次插入我的设备然后启动软件时,一切正常。如果我先启动软件然后插入设备,它没有检测到。我尝试使用 CyclePort 重新连接设备,但失败并显示状态 FT_OTHER_ERROR。在 Windows 设备管理器中,两种情况下都会检测并显示设备。驱动程序已经更新并手动安装。 关于导致这种情况的原因有什么想法吗?
这是我的代码:
List<string> pcdSerials = new List<string>();
FTDI ftdi = new FTDI();
UInt32 ftdiDeviceCount = 0;
FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
ftStatus = ftdi.GetNumberOfDevices(ref ftdiDeviceCount);
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
return pcdSerials;
}
FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
ftStatus = ftdi.GetDeviceList(ftdiDeviceList);
if (ftStatus != FTDI.FT_STATUS.FT_OK)
{
return pcdSerials;
}
foreach (var info in ftdiDeviceList)
{
if (info.Type == FTDI.FT_DEVICE.FT_DEVICE_UNKNOWN)
{
if (ftdiDeviceList.Count() == 1)
{
// The effect of this function is the same as disconnecting then reconnecting the device from USB.
// Possible use of this function is in situations where a fatal error has occurred and it is difficult,or not possible,to recover without unplugging and replugging the USB cable. This function can also be used after re-programming the EEPROM to force the FTDI device to read the new EEPROM contents which previously required a physical disconnect-reconnect.
ftStatus = ftdi.CyclePort();
if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
// Port has been cycled. Close the handle.
ftStatus = ftdi.Close();
}
else
{
// FT_CyclePort FAILED!
}
break;
}
}
if (info.Description != "FT232R USB UART")
continue;
if (info.Type != FTDI.FT_DEVICE.FT_DEVICE_232R)
continue;
pcdSerials.Add(info.SerialNumber);
}
return pcdSerials;
解决方法
这不是答案,而是评论。作为 Stack Overflow 的新手,它不会让我简单地为您的问题添加评论,或者我不知道我在做什么。 :) 我遇到了同样的问题。我在 10 多年前编写了一个包装类,它一直运行良好,直到客户端计算机上更新了新的 FTDI 驱动程序 2.12.36.1。 FTDI 于 2021 年 6 月 17 日发布了驱动程序版本 2.12.36.2,我希望它能解决问题,但它没有。 我发现调用 FT_CreateDeviceInfoList 确实返回了正确数量的连接设备。然后我调用 FT_GetDeviceInfoDetail 来获取设备类型、描述和 FTDI 序列号。设备类型作为值 0x03 返回,即 FT_Device_Unknown 并且描述和序列号似乎返回为空。我使用 FTDI 序列号通过序列号打开设备。没有有效的序列号,我无法打开设备。多年来,我一直使用这种方法作为 FTDI 的首选方法,直到现在都没有问题。 希望其他人可以提供答案,因为我有很多客户无法使用他们的 PC 连接到我的产品。 我将联系 FTDI 支持,看看他们是否可以解决这个问题。如果我听到回消息,我会在这里发帖。