First of all do not know what I am using the version is not low.
BUG following occurs:
1, only the PC's USB HID device I designed when all of the communication status, disconnected, connected. Communications. No problem!
2, when the PC has multiple HID devices exist, restart the application only to find my USB HID. Communication is no problem! But my USB HID connection is disconnected, the application could not find the HID device
After many days of my test application and found that the problem is DeviceAttributes.VendorID
Because the USB HID devices do not find clear! To procedural errors by the judge-type;
If (DeviceAttributes.VendorID = MyVendorID) And _
(DeviceAttributes.ProductID = MyProductID) Then
'It's the desired device.
'My device detected
MyDeviceDetected = True
Else
************************************************** ******************
Improved code:
Function FindTheHid () As Boolean
'Makes a series of API calls to locate the desired HID-class device.
'Returns True if the device is detected, False if not detected.
Dim Count As Integer
Dim GUIDString As String
Dim HidGuid As GUID
Dim MemberIndex As Long
LastDevice = False
MyDeviceDetected = False
'BUG -> there are multiple computer standard HID device, the device is disconnected, and then not work together with and must restart the program!
'Improved methods
'Set each enumeration USB HID device ID must first be cleared before!!
'Modified: November 10, 2011 Liang Xiliang 310902900@163.com
DeviceAttributes.VendorID = 0
DeviceAttributes.ProductID = 0
'Values for SECURITY_ATTRIBUTES structure:
Security.lpSecurityDescriptor = 0
Security.bInheritHandle = True
Security.nLength = Len (Security)
'************************************************* *****************************
'HidD_GetHidGuid
'Get the GUID for all system HIDs.
'Returns: the GUID in HidGuid.
'The routine doesn't return a value in Result
'But the routine is declared as a function for consistency with the other API calls.
'************************************************* *****************************
Result = HidD_GetHidGuid (HidGuid)
Call DisplayResultOfAPICall ("GetHidGuid")
'Display the GUID.
GUIDString = _
Hex $ (HidGuid.Data1) & "-" & _
Hex $ (HidGuid.Data2) & "-" & _
Hex $ (HidGuid.Data3) & "-"
For Count = 0 To 7
'Ensure that each of the 8 bytes in the GUID displays two characters.
If HidGuid.Data4 (Count)> = & H10 Then
GUIDString = GUIDString & Hex $ (HidGuid.Data4 (Count)) & ""
Else
GUIDString = GUIDString & "0" & Hex $ (HidGuid.Data4 (Count)) & ""
End If
Next Count
'GUID for system HIDs = GUIDString
'************************************************* *****************************
'SetupDiGetClassDevs
'Returns: a handle to a device information set for all installed devices.
'Requires: the HidGuid returned in GetHidGuid.
'************************************************* *****************************
DeviceInfoSet = SetupDiGetClassDevs _
(HidGuid, _
vbNullString, _
0, _
(DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE))
Call DisplayResultOfAPICall ("SetupDiClassDevs")
DataString = GetDataString (DeviceInfoSet, 32)