资源简介
HID USB通信的动态库,根据ProductID和VendorID来识别设备,可以直接调用使用;
压缩包包含源代码,VC++开发,应用于Window系统中程序和HID设备通信;
代码片段和文件信息
// HIDUSB.cpp : 定义 DLL 应用程序的入口点。
//
#include “stdafx.h“
#include “hidusb.h“
extern “C“ {
// Declare the C libraries used
#include “setupapi.h“ // Must link in setupapi.lib
#include “hidsdi.h“ // Must link in hid.lib
}
#ifdef _MANAGED
#pragma managed(push off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule
DWORD ul_reason_for_call
LPVOID lpReserved
)
{
return TRUE;
}
BOOL __stdcall DLLAPI SearchHIDDev(unsigned short nVendorID unsigned short nProductID int * piDevNum char * acInfo){
struct _GUID GUID;
int iRetErr;
SP_INTERFACE_DEVICE_DATA DeviceInterfaceData;
HANDLE PnPHandle=NULLHIDHandle=NULL;
struct {
DWORD cbSize;
char DevicePath[256];
} FunctionClassDeviceData;
HIDD_ATTRIBUTES HIDAttributes;
SECURITY_ATTRIBUTES SecurityAttributes;
int Device;
ULONG BytesReturned;
bool Success;
* piDevNum = 0;
// Initialize the GUID array and setup the security attributes for Win2000
HidD_GetHidGuid(&GUID);
SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor = NULL;
SecurityAttributes.bInheritHandle = false;
// Get a handle for the Plug and Play node and request currently active devices
PnPHandle = SetupDiGetClassDevs(&GUID NULL NULL DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
if (int(PnPHandle) == -1) {
strcpy(acInfo“Could not attach to PnP node.“);//printf(“Could not attach to PnP node“);
iRetErr = GetLastError();
return iRetErr;
}
// Lets look for a maximum of 22 Devices
for (Device = 0; Device < 22; Device++) {
// Initialize our data
DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);
// Is there a device at this table entry
Success = SetupDiEnumDeviceInterfaces(PnPHandle NULL &GUID Device &DeviceInterfaceData);
if (Success) {
// There is a device here get it‘s name
FunctionClassDeviceData.cbSize = 5;
Success = SetupDiGetDeviceInterfaceDetail(PnPHandle &DeviceInterfaceData
(PSP_INTERFACE_DEVICE_DETAIL_DATA)&FunctionClassDeviceData 256 &BytesReturned NULL);
if (!Success) {
strcpy(acInfo“Could not find the system name for this device.“);
iRetErr = GetLastError();
if(PnPHandle)
SetupDiDestroyDeviceInfoList(PnPHandle);
return iRetErr;
}
// Can now open this device
HIDHandle = CreateFile(FunctionClassDeviceData.DevicePath GENERIC_READ|GENERIC_WRITE
FILE_SHARE_READ|FILE_SHARE_WRITE &SecurityAttributes OPEN_EXISTING 0 NULL);
if (HIDHandle == INVALID_HANDLE_VALUE)
sprintf(acInfo“Could not open HID #%d Errorcode = %d\n“ Device GetLastError());
else {
// Get the information about this HID
Success = HidD_GetAttributes(HIDHandle &HIDAttributes);
if (!Success) {
strcpy(acInfo“Could not get HID attributes.“);
iRetErr = GetLastError();
if(PnPHandle)
SetupDiDestroyDeviceInfoList(PnPHa
- 上一篇:网络主机的存活性探测系统设计与实现VC
- 下一篇:车牌识别与定位C++
相关资源
- QT实现USB摄像头拍照
- usb键盘(MyUSB_HID_KEIL)
- usb之CDC(CDC_Standalone.rar)
- Linux那些事儿之我是USB core
- USB CAN Tool 源代码(LabVIEW 2011环境)
- VC6 USB开发源码
- stm32f103 USB键盘
- c++监控USB插拔状态源码
- USB识别 HID识别 MFC代码
- USB 完整bootloader项目,包括底层驱动和
- USB2.0接口数据采集卡
- 基于VC MFC的数据分析系统
- 基于C++的虚拟串口通讯
- USB双向通信上位机VC++程序
- hid usb 编程源码
- 基于CY7C68013A的USB2.0详细开发文档
- USB视频设备采集图像VisualC++程序
- 基于C++的USB的数据传输的上位机程序
- 真正的usbview源代码
- vc++调用usb摄像头,进行拍照,保存为
- VC6.0+MFC+USBCAN上位机通信控制
- USB3300上位机端数据收发Demo最大速度
- vcMfcUsbPort完整上位机源码
- USB HID上位机源代码
- USB视频设备采集图像VisualC
- VC++USB通讯
- usb2187数据采集卡的程序
- USB3.0发送与接收数据c++版本
- USB 3.0编程宝典.pdf
- libusb bulk传输 STM32上位机程序
评论
共有 条评论