PORTS Forum

Ports and Interfaces => USB => Topic started by: DavidClarke on June 13, 2019, 12:46:52 pm

Title: A strange new problem after changing hardware.
Post by: DavidClarke on June 13, 2019, 12:46:52 pm

Some background:

Hardware 1 - Part 1:
===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x02  -> Direction: OUT - EndpointID: 2
bmAttributes:                      0x03  -> Interrupt Transfer Type
wMaxPacketSize:                  0x0400 = 1 transactions per microframe, 0x400 max bytes
bInterval:                         0x01

I have a program that successfully sends an output report to a device (Stream Deck Mini) using WriteFile.  The report id is 2 so I send 2 followed by 1023 bytes of data.  It works just great.  i can even send 2 followed by 1023 null bytes and WriteFile  still returns success and there are no errors.  wMaxPacketSize: 0x0400   is how I know to send 1024 bytes.  So far so good.


Hardware 2 - Part 2:
===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x02  -> Direction: OUT - EndpointID: 2
bmAttributes:                      0x03  -> Interrupt Transfer Type
wMaxPacketSize:                  0x0200 = 1 transactions per microframe, 0x200 max bytes
bInterval:                         0x01

Now I change the hardware (Stream Deck 15 button) - Since the wMaxPacketSize: 0x0200  for this device is 512 bytes I make adjustments to my code and send report 2 --  a 2 followed by 511 bytes.  WriteFile returns an error 87 ERROR_INVALID_PARAMETER.  No mater what I do it keeps returning error 87.  I have a Beagle analyzer and I can see the 512 bytes of data being send by the FACTORY PROVIDED software - but when my software tries to send the exact same 512 bytes i get the error (87).

The WriteFile function only has a couple of arguments - WriteFile(HandleWriteFile, WRITE_BUFFER, BYTES_IN_BUFFER, BYTES_WRITTEN) - And this function works fine for the 1024 byte hardware.

Part of my question is - how smart is the HID driver?  I would get it if the driver would error if I had the wrong report id or byte length. 
When I use USB Device Viewer (microsoft) the hardware looks exactly the same except for the max bytes on the output report.

It is moments like this when I wish I could see deeper into windows to figure out why the WriteFile function thinks I am passing an invalid parameter, especially when the other hardware doesn't cause the same problem.

Weird!






Title: Re: A strange new problem after changing hardware.
Post by: Jan Axelson on June 13, 2019, 04:40:32 pm
WriteFile should send the whole report + report ID. Don't worry about MaxPacketSize. Dividing the report into multiple transactions when needed is handled at a lower level.
Title: Re: A strange new problem after changing hardware.
Post by: DavidClarke on June 13, 2019, 05:55:46 pm
I think you are saying...  No mater what size the data you are sending, send it with one WriteFile call, right?

So not this:

For i 1 to 10
 WriteFile (BYVAL HandleWriteFile, WRITE_BUFFER, 1024, BYTES_WRITTEN) 
next

Do this?

WriteFile (BYVAL HandleWriteFile, WRITE_BUFFER, 10,240, BYTES_WRITTEN) 

I will give that a try.



Title: Re: A strange new problem after changing hardware.
Post by: DavidClarke on June 13, 2019, 06:14:20 pm
You were right!  One WriteFile call.