Author Topic: Walking through the demo code, many more questions  (Read 10526 times)

focusrsh

  • Member
  • ***
  • Posts: 4
Walking through the demo code, many more questions
« on: March 13, 2016, 01:26:26 pm »
OK, let  me say upfront that I'm (clearly!) brand new to USB coding.  So as my mother would say, "Be nice!"

I've got a heavy-deadline project that uses an HOBO temperature logger (from Onset Computers) that has a USB connector, and I need to periodically stop it and download the temperature log.  (By the way, it is a really nice device.  Inexpensive and works great.)  After signing an NDA with the company, I have a 95 page doc with the interface API.  It is an HDI device and all commands written to it are 8-bytes long.  The main application that needs to talk to it is written in VB.Net, hence my looking at the WinUSB code.

I've been walking through the demo code from this site.  A few questions....
1.
In the file frmMain.vb, function FindDeviceUsingWmi, there is the statement
Const classGuid As String = "88bae032-5a81-49f0-bc3d-a4ff138216d6"
Visual Studio reports this as an unused variable.

Is this just detritus from previous coding that author didn't remove, or am I suppose to use it somewhere?

2.
There is a definition at the top of the class constructor
         Private Const DeviceInterfaceGuid As String...
where the comments say I should change it to match the GUID of the device.  Not having that, I changed the PID and VID constants  (also in the class constructor) to match the HOBO device, and when the demo program runs, it reports a GUID.  Should I copy that into this constant definition?  (I did read the info on this website about looking in the manufacturer's INF file for the device, but there wasn't one provide.  The support software is an *.exe file that installs everything.)

Is there a way through Windows to find the GUID?  Device manager doesn't report it.

3.
In formMain.FindMyDevice, there is line
          Dim deviceFound = _myDeviceManagement.FindDeviceFromGuid(winUsbDemoGuid, devicePathName)
I've verified the GUID matches what I discussed above, but this always reports FALSE.
What is going on here?

4.
Since the above always reports FALSE, then the variable _deviceReady is never set TRUE.  (It is only ever set TRUE in function frm.FindMyDevice.)
The function then goes on to call FindDeviceUsingWmi().  That function does succeed, based on the PID/VID I provided.  But it never sets _deviceReady TRUE. 
Should it?  Is this a bug?

5.  Since _deviceReady is not set TRUE, then the function SendAndReceiveViaBulkTransfers() never executes RequestToSendDataViaBulkTransfer().

OK, enough questions.  Seems like there are some real bugs here.  Anyone else get this code to work?


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Walking through the demo code, many more questions
« Reply #1 on: March 13, 2016, 02:45:46 pm »
In Device Manager, do you see WinUSB assigned to the device (Driver > Driver details). In your other post, you mention talking to a HID device. If the device is HID class, you need to use the HID driver and interface, not WinUSB.

1. See the comment just above the definition:

' ClassGUID value from Windows-provided winusb.inf for use if you want to search by ClassGUID.

2. If using the system-provided winusb.inf, this GUID must match the GUID in the device's
 extended properties OS feature descriptor.

If you are writing the application to talk to a device, the device vendor should provide this information, or you can retrieve it using a protocol analyzer on device attachment.

focusrsh

  • Member
  • ***
  • Posts: 4
Re: Walking through the demo code, many more questions
« Reply #2 on: March 13, 2016, 03:44:59 pm »
Hi and thanks for the help.

Unfortunately, I have so little experience working with USB devices that I don't know how to answer your questions.  I'll try my best.

-----------------
When I plug in the device, Device Manager reports TWO new items under Human Interface Device.
One is labeled USB Input Device, and in the driver details, it report
   C:\Windows\system32\DRIVERS\hidclass.sys
   C:\Windows\system32\DRIVERS\hidparse.sys
   C:\Windows\system32\DRIVERS\hidusb.sys
The other one is labeled HID-complaint device, but has no driver details listed.

Under the heading Universal Serial Bus controllers, nothing new is added.

-----------------------

>>If the device is HID class, you need to use the HID driver and interface, not WinUSB.

Sorry, this means nothing to me.  I thought WinUSB was the bottom part of the stack to any USB device, and that HID was an abstraction layered on top.

------------------
>>1. See the comment just above the definition:
>>' ClassGUID value from Windows-provided winusb.inf for use if you want to search by ClassGUID.

As I said in the post, that variable is not used anywhere.  It is an unused local constant.

Below it are some commented-out "if(queryObj).."  lines.
Am I suppose to replace the line "If queryObj("PNPDeviceID").ToString().Contains(deviceIdString) Then" with one of them?

If that is the case, there still isn't anything in that block of code that sets variable _deviceReady to true, which means none of the communication functions used later will proceed, since they all check that variable before attempting to send/receive.

Examining other parts of the code, I see that in the FindMyDevice() function, it calls myWinUSBCommunications.InitializeDevice which returns handles, device speed information and such.

Those calls are NOT in FindDeviceUsingWmi() function.  Shouldn't they be, so that the functions that send data know those parameters?

------------------
>>If you are writing the application to talk to a device, the device vendor should provide this information, or you can retrieve it using a protocol analyzer on device attachment.

The company is not very forthcoming.  As I mentioned, they required a signed NDA before I could get the doc.  The doc has lots of details about the command codes to send and what is returned, but essentially nothing about how to set up communications to the device.  Here is what they write:

"Host to Logger communications happens on multiple levels.  Here is a host to logger overview of the levels that communications goes through so a Windows application can access a datafile or sensor readings.

Client Host Application
Hid User Mode Library (includes HidD_SetFeature(), ReadFile(), etc.)
USB Library (System, Kernel)
...<snip>...

For low speed U-Family Devices, commands are sent from the Host to the USB device via 8-byte HID Feature Reports.  Command data and command confirmation is returned to the host from the USB dev9ice via one or more 8-byte HID Interrupt Input Reports.  The number of return packets are specific to each command and the host should know to clear extra interrupt inputs packs for each command sent to avoid getting out of sync."

--------------------

Bottom line:  Am I totally wasting my time trying to get the demo code to talk to this device?  This is frustrating in the extreme.  Doesn't help that I'm working 14 hours a day 7 days a week (not an exaggeration) on this project and this temperature logger is only a tiny part. 

Well, anyway, thanks for the help so far.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Walking through the demo code, many more questions
« Reply #3 on: March 13, 2016, 09:25:37 pm »
WinUSB is for devices that don't have a supported USB driver in the host system. For your device, you need to use the HID driver and API.

You can start with my HID example code. You will need to edit the code to match the length of the device's Feature and Input reports. Also comment out the code that waits for a Feature report after sending a report, and comment out the code that sends an Output report before retrieving an Input report. Then you can send a Feature report, and retrieve an Input report.

If you lack documentation, a protocol analyzer will show you the report descriptor with information about the reports.

If all of this is new to you, you will have a learning curve. My book and the information and code on my HID page will help.

http://janaxelson.com/hidpage.htm

http://janaxelson.com/development_tools.htm#analyzers