使用C#扫描人机接口设备(HID) [英] Scanning for a Human Interface Device (HID) using C#

查看:382
本文介绍了使用C#扫描人机接口设备(HID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发C#.NET 2.0应用程序,其中需要扫描附加的HID。如何才能做到这一点?因为它是HID,所以Windows不会为其分配COM端口。我只需要以编程方式确定设备是否已连接。谢谢。

I am developing a C# .NET 2.0 application wherein I need to scan for an attached HID. How can this be done? Because it is a HID, Windows does not assign a COM port to it. I only need to programmatically determine if the device is attached. Thank you.

其他信息

ADDITIONAL INFORMATION

何时我将USB设备连接到计算机时,在设备管理器中的人机界面设备下出现两个条目。单击其属性可在其各自的详细信息选项卡中产生此信息:

When I connect the USB device to my computer two entries appear under Human Interface Devices in the Device Manager. Clicking into their Properties yields this information in their respective Details tabs:

符合HID的设备
设备实例ID:HID\ VID_1795& PID_6004\7& 2694D932& 0& 0000

HID-compliant device Device Instance Id: HID\VID_1795&PID_6004\7&2694D932&0&0000

USB人机接口设备
设备实例ID:USB\VID_1795& ; PID_6004\B973000000EB0D00

USB Human Interface Device Device Instance Id: USB\VID_1795&PID_6004\B973000000EB0D00

推荐答案

在WMI代码创建器中,选择以下选项:

In the WMI Code Creator select these options:

名称空间:root\WMI

Namespace: root\WMI

类:MSWmi_PnPInstanceNames

Class: MSWmi_PnPInstanceNames

选择实例名称从结果框中获取以下代码:

Select InstanceNames from the Results box for the following code:

using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher = 
                    new ManagementObjectSearcher("root\\WMI", 
                    "SELECT * FROM MSWmi_PnPInstanceNames"); 

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("MSWmi_PnPInstanceNames instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("InstanceName: {0}", queryObj["InstanceName"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}

这篇关于使用C#扫描人机接口设备(HID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆