您的位置:首页 > 其它

打开设备和建立连接

2008-07-16 09:25 218 查看
打开一个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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐