打开设备和建立连接

 打开一个USB设备,首先要找到设备的Symboliclink Name,然后由其作为参数打开设备。

在此前应首先调用三个函数:

1.SetupDiGetClassDevs()

例://Get a list of devices matching the criteria (hid interface, present)
    hardwareDeviceInfoSet = SetupDiGetClassDevs (&hidGUID,
                                                NULL, // Define no enumerator (global)
                                                NULL, // Define no
                                                (DIGCF_PRESENT ¦ // Only Devices present
                                                DIGCF_DEVICEINTERFACE)); // Function class devices.

2.SetupDiEnumDeviceInterfaces()

例://Go through the list and get the interface data//枚举设备
result = SetupDiEnumDeviceInterfaces (hardwareDeviceInfoSet,
                                          NULL, //infoData,
                                          &hidGUID, //interfaceClassGuid,
                                          deviceIndex,
                                          &deviceInterfaceData);

3.SetupDiGetDeviceInterfaceDetail()

例://Get the details with null values to get the required size of the buffer//获detaildata结构数组的长度SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
                                    &deviceInterfaceData,
                                    NULL, //interfaceDetail,
                                    0, //interfaceDetailSize,
                                    &requiredSize,
                                    0); //infoData))
然后再调用一次SetupDiGetDeviceInterfaceDetail获得具体细节

此外,Get_att_capab()可以通过PID和VID找到合适的设备

然后用Createfile打开设备

//Open file on the device
    deviceHandle = CreateFile (deviceDetail->DevicePath, 
                              GENERIC_READ ¦ GENERIC_WRITE,
                              FILE_SHARE_READ ¦ FILE_SHARE_WRITE,
                              NULL,        // no SECURITY_ATTRIBUTES structure
                              OPEN_EXISTING, // No special create flags
                              0,
                              NULL);      // No template file

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值