打开设备和建立连接
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
在此前应首先调用三个函数:
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
相关文章推荐
- 苹果新专利:用摄像头在两台设备之间建立连接
- (转载)表服务器无法打开与报表服务器数据库的连接。所有请求和处理都要求与数据库建立连接。
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连
- Ubuntu VPS中wordpress网站打开时提示”建立数据库连接错误”的解决办法
- 表服务器无法打开与报表服务器数据库的连接。所有请求和处理都要求与数据库建立连接。
- "报表服务器无法打开与报表服务器数据库的连接。所有请求和处理都要求与数据库建立连接。"错误解决
- Bluetooth设备之间如何建立连接
- (转载)表服务器无法打开与报表服务器数据库的连接。所有请求和处理都要求与数据库建立连接。
- 关于DM8168的SATA接口与SATA3设备连接建立失败的问题
- ios助手开发系列(三):打开设备连接,获取设备基本信息
- 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)
- 用vs.net新建web项目时提示错误“尝试创建web项目或打开位与http://localhost/webapplication1的web项目时无法与服务器建立连接”
- (转载)表服务器无法打开与报表服务器数据库的连接。所有请求和处理都要求与数据库建立连接。
- 建立设备管理连接
- win8.1升级IE11浏览器打开网页提示‘远程计算机或设备将不接受连接’
- PC与Android设备通过USB建立通信连接
- android开发(20) 使用adb建立pc和android设备之间的连接。usb连接方式。
- EntityFramework.SqlServer.dll 中发生 其他信息: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)
- 通过设备符号连接打开设备 句柄得到设备名_ZwOpenSymbolicLinkObject_ZwQuerySymbolicLinkObject