从.NET应用程序在Windows 7下找到USB串口串口、应用程序、NET、USB

由网友(泰山府君)分享简介:我有一个看起来与定制USB描述一个特定的FTDI串行端口的应用程序。我现在的code使用从实例code项目,该搜索在的 MSSerial_PortName WMI表根\ WMI ,翻出从 ROOT \ CIMV2 \ WIN32_PnPEntity 额外的USB的信息。I have an application t...

我有一个看起来与定制USB描述一个特定的FTDI串行端口的应用程序。我现在的code使用从实例code项目,该搜索在 MSSerial_PortName WMI表根 WMI ,翻出从 ROOT CIMV2 WIN32_PnPEntity 额外的USB的信息。

I have an application that looks for a specific FTDI serial port with customised USB descriptors. My current code uses the example from Code Project, which searches the MSSerial_PortName WMI table under rootWMI, and pulls out extra USB information from rootCIMV2WIN32_PnPEntity.

这行之有效XP下,但应用程序也必须在一个标准用户在Windows上7. 根这样的环境中访问 WMI 结果访问被拒绝运行 ManagementException

This worked well under XP, but the application must also run under a standard user onWindows 7. In this environment access of rootWMI results in an "Access Denied" ManagementException.

任何人都可以提出一个方法交叉引用一个串行端口的USB信息的DOS设备名,而运行作为一个标准用户?到目前为止,我已经看了 ROOT CIMV2 WIN32_SerialPort * 表,但它们只包含主板端口。我也考虑过用 SetupAPI的,但我还没有找到一个完整的工作PInvoke的模板这一点。

Can anybody suggest a way to cross reference the DOS device name of a serial port to the USB information, while running as a standard user? So far I've looked at the rootCIMV2WIN32_SerialPort* tables, but they only contain motherboard ports. I've also considered using SetupAPI, but I haven't found a complete and working PInvoke template for this.

推荐答案

我发现一个答案适合我们的情况下,虽然没有一个通用的。我们的USB转换器都FTDI和FTDI提供 DLL处理这个。我使用的DLL code是如下:

I've discovered an answer suitable for our case, though not a generic one. Our USB converters are all FTDI, and FTDI provide a DLL that handles this. My code using the DLL is below:

UInt32 count = 0;
FTDI.FT_STATUS status = ftdi.GetNumberOfDevices(ref count);
if (status != FTDI.FT_STATUS.FT_OK)
{
    log.Warn("Unable to access FTDI");
    return ports;
}
FTDI.FT_DEVICE_INFO_NODE[] list = new FTDI.FT_DEVICE_INFO_NODE[count];
status = ftdi.GetDeviceList(list);
if (status != FTDI.FT_STATUS.FT_OK)
{
    log.Warn("Unable to access FTDI");
    return ports;
}
foreach (FTDI.FT_DEVICE_INFO_NODE node in list)
{
    if ((status = ftdi.OpenByLocation(node.LocId)) == FTDI.FT_STATUS.FT_OK)
    {
        try
        {
            string comport;
            ftdi.GetCOMPort(out comport);
            ports.Add(new Port(comport, node.Description, node.SerialNumber));
        }
        finally
        {
            ftdi.Close();
        }
    }
}
阅读全文

相关推荐

最新文章