I'm a 65 year old student (of life, and many things) and I am looking for someone to give me a steer in what looks like good USB code but comes up with nothing when it tries to enumerate HID devices. I'm exploring hooking up serial data via a USB port (COM ports have vanished from laptops) from marine instrumentation such as GPS data. Got a little yacht when I retired!
I grabbed two sets of code from the Internet and going into the code, as far as the "sticking point", they look almost identical. I know enough to check all the declares and data structures etc, and all looks OK. I don't get a failure, just a lack of return on the enumeration. I've looked over the USB spec and tried to understand why HID was selected by the original coders. Looks like the mouse and my external USB drive are excluded from HID - as special classes. I expected to "find something" however in the enumeration. There is a keyboard, a scanner, a printer, and a bluetooth device
This code compiles and runs without error, but never discovers any USB devices....
Public Function OpenUSBdevice(NameOfDevice$) As Boolean
' This function searches the system HID (Human Interface Device) tables for NameOfDevice$
' If found then it opens the device and returns TRUE, else it returns FALSE
Dim HidGuid As Guid: Dim Success As Boolean: Dim Openned As Boolean: Dim Buffer(256) As Byte
Dim DeviceInterfaceData As Device_Interface_Data
Dim FunctionClassDeviceData As Device_Interface_Detail
'
' First, get the HID class identifier
Call HidD_GetHidGuid(HidGuid.Data(0))
' Get a handle for the Plug and Play node, request currently active HID devices
PnPHandle& = SetupDiGetClassDevs(HidGuid.Data(0), 0, 0, &H12)
If (PnPHandle& = -1) Then ErrorExit ("Could not attach to PnP node")
'
HidEntry& = 0: Openned = False
DeviceInterfaceData.cbsize = 28 'Length of data structure in bytes
' Look through the table of HID devices
Do While SetupDiEnumDeviceInterfaces(PnPHandle&, 0, HidGuid.Data(0), HidEntry&, DeviceInterfaceData.cbsize)
' There is a device here, get it's name *******NEVER GETS HERE
I suspect it's not a coding problem but something else I don't yet comprehend.

New Topic/Question
Reply




MultiQuote





|