USB Port Enumeration returns nothing

USB Enumeration Failure, but is Code the Culprit?

Page 1 of 1

2 Replies - 4466 Views - Last Post: 01 November 2009 - 05:04 PM Rate Topic: -----

#1 KJB  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 28-October 09

USB Port Enumeration returns nothing

Post icon  Posted 29 October 2009 - 04:18 PM

Coding in VB6. (Have .net and have done some c#, but any advantage to change?)

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.

Is This A Good Question/Topic? 0
  • +

Replies To: USB Port Enumeration returns nothing

#2 bytelogik  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 212
  • Joined: 06-October 09

Re: USB Port Enumeration returns nothing

Posted 30 October 2009 - 10:24 AM

http://www.planet-so...p...14&lngWId=1

http://www.planet-so...p...67&lngWId=1

Hope this helps.

keep smiling.
Was This Post Helpful? 0
  • +
  • -

#3 KJB  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 28-October 09

Re: USB Port Enumeration returns nothing

Posted 01 November 2009 - 05:04 PM

View Postbytelogik, on 30 Oct, 2009 - 09:24 AM, said:




Ran the code from your first reference link, and this worked "straight out of the box", enumerating all the hard drives and a USB memory stick I had plugged in. It did not enumerate my printer or scanner however. This leaves me thinking my original code was OK, and the problem is that the class of device "Human Interface Device" is a somewhat arbitrarily selection by the manufacturer. In other words, I had no HIDs plugged when I tried to find them. So when I eventually talk to the data stream from my GPS unit -via a serial to USB adapter- goodness knows what class of device I should expect. Bet you a pound to a penny that the vendor won't have a clue either if I ask.

That was instructive. Thank you.

Ken
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1