Author Topic: Chapter 13: Sending an Output Report to the Device  (Read 11843 times)

phadley

  • Member
  • ***
  • Posts: 6
Chapter 13: Sending an Output Report to the Device
« on: January 24, 2011, 09:46:07 am »
I have two problems sending output reports to my HID from my .NET application:

1) In my copy of the USB Complete book, the code to marshal the write buffer to un-managed memory is missing. (page 328)  Is this a mistake, or is it intentional?  Without it, my application sometimes writes bad data to my HID.  It was tricky to find the problem because the bug was intermittent, and only on certain PCs.  (I have also read that the numBytesWritten parameter to Writefile should be marshalled as well.  For both parameters, I use Marshal.AllocHGlobal() to allocate unmanaged memory, copy the value, and then pass IntPtr to WriteFile.)

2) When I use a USB 2.0 hub to communicate with my device, I get 0 back from numBytesWritten after a successful WriteFile (or a successful GetOverlappedResult).  My USB snooper sees three CSPLIT transmissions of the data between the PC and the hub.  However, the snooper sees none of this data between the hub and the device.  Is there something special I have to do in my software to support USB 2.0 hubs??

Thanks.

Phil

 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Chapter 13: Sending an Output Report to the Device
« Reply #1 on: January 24, 2011, 10:24:29 am »
1. My website has the most current and robust versions of the code:

http://www.lvr.com/hidpage.htm#MyExampleCode

2. No.

Jan

phadley

  • Member
  • ***
  • Posts: 6
Re: Chapter 13: Sending an Output Report to the Device
« Reply #2 on: January 24, 2011, 03:28:54 pm »
Thanks for your reply!  Follow up questions:

1)  The code posted here also does not marshall the write buffer to un-managed memory.  The bug I get using this code shows up as garbage data on the device, but only intermittently, and when I send the report continuously, and from one particular application.  I fixed the problem by marshalling the buffer and passing an IntPtr to the unmanaged memory to WriteFile.

2)  I agree with you that no software changes should be necessary.  Can you give any suggestions as to what's causing the problem?

Phil

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Chapter 13: Sending an Output Report to the Device
« Reply #3 on: January 24, 2011, 05:59:38 pm »
1. Thanks for reporting this.

2. Connect the protocol analyzer between the device and hub to find out what is happening at the device. If you're using a software analyzer, use whatever debugging tools you have to find out how the device is responding to received OUT packets.

Jan 

phadley

  • Member
  • ***
  • Posts: 6
Re: Chapter 13: Sending an Output Report to the Device
« Reply #4 on: January 25, 2011, 09:19:02 am »
One more follow up:

2)  I tried connecting the USB snooper on either side of the hub, and none of the data that I sent appears between the hub and the device.  However, between the PC and the hub, I see three CSPLIT transmissions, each one containing the entire report.  It's like the PC makes three attempts at sending the data (which gets blocked by the hub), and then gives up.

Any advice or direction for troubleshooting this problem would be very appreciated, and thanks for doing this PORTS forum!

Phil

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Chapter 13: Sending an Output Report to the Device
« Reply #5 on: January 25, 2011, 12:25:25 pm »
For an OUT transaction, the host should send the data in the SSPLIT transaction. What does the hub return? The hub may NAK the transaction but should return ACK on a later try. Only then does the hub initiate and complete the transaction with the device.

Is the device a HID? Is WriteFile using an interrupt endpoint or the control endpoint? If it's an interrupt endpoint, does the device have an enabled interrrupt OUT endpoint?

Jan

phadley

  • Member
  • ***
  • Posts: 6
Re: Chapter 13: Sending an Output Report to the Device
« Reply #6 on: January 25, 2011, 01:37:59 pm »
The device is a HID device.  It has interrupt endpoints enabled for both IN and OUT.

Would it help if I posted the Ellisys UFO file?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Chapter 13: Sending an Output Report to the Device
« Reply #7 on: January 25, 2011, 05:00:44 pm »
sure

Jan