如何從C++中擷取數位板(USB)訊號 |
尚未結案
|
shingo
一般會員 發表:3 回覆:1 積分:0 註冊:2004-10-11 發送簡訊給我 |
|
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
jimmy_and_you
初階會員 發表:20 回覆:74 積分:33 註冊:2003-05-12 發送簡訊給我 |
數位板應該算是一個HID的裝置吧,下面這一段CODE你可以參考:
bool __fastcall TAboutBox::CheckHIDDevice(unsigned short PID, unsigned short VID) { struct _GUID GUID; SP_INTERFACE_DEVICE_DATA DeviceInterfaceData; struct {DWORD cbSize; char DevicePath[256];} FunctionClassDeviceData; HIDD_ATTRIBUTES HIDAttributes; SECURITY_ATTRIBUTES SecurityAttributes; int Device; HANDLE PnPHandle; HANDLE HIDHandle; ULONG BytesReturned; bool Success; WCHAR ManufacturerBuffer[256], ProductBuffer[256]; bool ans = false; //printf("Display currently attached Human Interface Devices\n\n"); // 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) { // printf("Could not attach to PnP node"); // return GetLastError(); return false; } // Lets look for a maximum of 20 Devices for (Device = 0; (Device < 20); 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) { // printf("Could not find the system name for this device\n"); // return GetLastError(); return false; } // Can now open this device HIDHandle = CreateFile(FunctionClassDeviceData.DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, &SecurityAttributes, OPEN_EXISTING, 0, NULL);//-->可用這個FILE HEADER W/R 資料 if (HIDHandle == INVALID_HANDLE_VALUE) { // printf("Could not open HID #%d, Errorcode = %d\n", Device, GetLastError()); break; } else { // Get the information about this HID Success = HidD_GetAttributes(HIDHandle, &HIDAttributes); if (!Success) { // printf("Could not get HID attributes\n"); // return GetLastError(); return false; } // And display it! // printf("VID = %4.4x, Name = ", HIDAttributes.VendorID); // printf("%s, ", ManufacturerName ? strManufacturer.c_str() : "NULL"); // printf("PID = %4.4x, Name = ", HIDAttributes.ProductID); // printf("%s\n", ProductName ? strProduct.c_str() : "NULL"); if( PID == HIDAttributes.ProductID && VID == HIDAttributes.VendorID ) { getManufacturerName = HidD_GetManufacturerString(HIDHandle, ManufacturerBuffer, 256); getProductName = HidD_GetProductString(HIDHandle, ProductBuffer, 256); strManufacturer = WideCharToString(ManufacturerBuffer); strProduct = WideCharToString(ProductBuffer); ans = true; //CloseHandle(HIDHandle); MyHIDHandle = HIDHandle; break; } else CloseHandle(HIDHandle); } } // if (SetupDiEnumDeviceInterfaces . . } // for (Device = 0; (Device < 20); Device ) SetupDiDestroyDeviceInfoList(PnPHandle); return ans; } |
shingo
一般會員 發表:3 回覆:1 積分:0 註冊:2004-10-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |