Author Topic: USB HID w/RFID reader  (Read 19420 times)

kberisso

  • Member
  • ***
  • Posts: 7
USB HID w/RFID reader
« on: December 28, 2011, 11:59:54 am »
Dear Jan,

Good morning. I am working with a USB HID RFID reader (radio frequency id) and am having a bit of trouble. I have your book (USB Complete 4th ed) and have tried downloading the code from the website, but even the basic demo app seems to crash on a regular basis. I have been looking into other solutions and just can’t seem to get things licked.
 
First off, I should warn you I am not the best of programmers. However, having said that, I can usually figure things out with a bit of specific help/direction. The problems I seem to have with the demo on your web page is that the app keeps dying during the report exchange. I also get errors in the WndProc override.
 
Using the LibUsbDotNet tools, I get the following info about my device. As you will see, it is a fairly basic device and the software I am working on is specific for this hardware, so I don’t necessarily need to “learn” about the device – I can hard code much of the info such as report sizes. As a result, I have tried to comment out the sections that get the report sizes - still no luck.
 
Standard system devices) - USB Input Device OSVersion:Microsoft Windows NT 6.1.7601 Service Pack 1 LibUsbDotNet Version:2.2.8.104 DriverMode:LibUsb
Length:18
DescriptorType:Device
BcdUsb:0x0110
Class:PerInterface
SubClass:0x00
Protocol:0x00
MaxPacketSize0:64
VendorID:0x1325
ProductID:0xC029
BcdDevice:0x0000
ManufacturerStringIndex:1
ProductStringIndex:2
SerialStringIndex:0
ConfigurationCount:1
ManufacturerString:MTI
ProductString:RU-888
SerialString:

CONFIG #1
Length:9
DescriptorType:Configuration
TotalLength:41
InterfaceCount:1
ConfigID:1
StringIndex:0
Attributes:0x80
MaxPower:250
ConfigString:

INTERFACE (0,0)
Length:9
DescriptorType:Interface
InterfaceID:0
AlternateID:0
EndpointCount:2
Class:Hid
SubClass:0x00
Protocol:0x00
StringIndex:0
InterfaceString:

ENDPOINT 0x81
Length:7
DescriptorType:Endpoint
EndpointID:0x81
Attributes:0x03
MaxPacketSize:64
Interval:10
Refresh:0
SynchAddress:0x00

ENDPOINT 0x02
Length:7
DescriptorType:Endpoint
EndpointID:0x02
Attributes:0x03
MaxPacketSize:64
Interval:10
Refresh:0
SynchAddress:0x00
 
 
I am developing on a Win7, 64bit machine with c#.

Thanks

Kevin

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB HID w/RFID reader
« Reply #1 on: December 28, 2011, 12:11:14 pm »
See:

http://www.lvr.com/forum/index.php?topic=696.0

What line of code is causing an error and what is the error? Use breakpoints and single-stepping if needed to isolate the problem.

Jan


kberisso

  • Member
  • ***
  • Posts: 7
Re: USB HID w/RFID reader
« Reply #2 on: December 28, 2011, 12:48:17 pm »
OK. I have updated things per the referenced post and here is what is happing:

When I run the software without break points, it will get as far as trying to register for notifications in the FindTheHid routine. When it dies, I get the following as the last message in the debugger.

"The OS is more recent than Windows 98 Gold.The program '[6816] GenericHid.vshost.exe: Managed (v2.0.50727)' has exited with code -1073740940 (0xc0000374)."

If, however, I manually step through the remainder of the code beyond the "if(myDeviceDetected)" line, then all is ok. I tried putting in some 20ms sleep statements, but that didn't seem to matter...  :'(

Thanks

Kevin

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB HID w/RFID reader
« Reply #3 on: December 28, 2011, 03:13:40 pm »
So if you comment out registering for device notifications, the application works (except for notifications)?

What line of code causes the error?

Jan

kberisso

  • Member
  • ***
  • Posts: 7
Re: USB HID w/RFID reader
« Reply #4 on: January 02, 2012, 04:34:44 pm »
Ok. Here is what I have found after some more testing. It seems that
    "MyHid.Capabilities = MyHid.GetDeviceCapabilities(hidHandle);"

is causing the problems... For some reason if I comment this out and manually add in the capability values then I am in good shape. If I step through GetDeviceCapabilities, all is ok - no problems. However, whenever I let the software run through on it's own, I am back at the

"The program '[4776] GenericHid.vshost.exe: Managed (v2.0.50727)' has exited with code -1073740940 (0xc0000374) " error.

So my two questions at this point are:
1) do you have any ideas on what might be causing the problem. Because of what I am doing, I can cheat and hardcode all of the capabilities in.
2) Can you think of any where that not using the GetDeviceCapabilities might cause problems?

Thanks

Kevin

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB HID w/RFID reader
« Reply #5 on: January 03, 2012, 11:02:42 am »
Retrieving the device capabilities is optional. A host that knows what to do with the report data doesn't have to ask for the capabilities.

I don't know why you're seeing the error.

To isolate the problem further, you could put a breakpoint halfway through the routine that is crashing the program.

If the program crashes, move the breakpoint 1/4 of the way in the routine and retest.

If the program reaches the breakpoint without crashing, move the breakpoint 3/4 of the way through the routine and retest.

Continue until you find the problem line.

Jan