PORTS Forum
Ports and Interfaces => USB => Topic started by: DavidClarke on May 08, 2019, 06:07:08 pm
-
Hi
Do you have any old example code in plain C with Win32API? One person suggested I order an old copy of your USB book. I found a volume 3 and it is on its way. I have to use PowerBasic to add functionality to an existing large bit of code. PowerBasic can call Win32Api just fine. You can do most anything in PowerBasic that you can do in C.
I got a Beagle USB 480 but my device doesn't light up when plugged into the Beagle. Before I purchased I asked the Beagle people if the 480 could supply 300ma to the device and they said no problem. So protocol analyzer is not helping yet.
I am 50% of the way to having this working - receiving button press events work great with ReadFile + WaitForSingleObject.
Data is simple (01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00) Bytes 2 - 7 are 1 when the buttons are pressed.
I have a software usb analyzer. I can see the data going to the device as changes are made. This data (05 55 AA D1 01 64 00 00 00 00 00 00 00 00 00 00 00) should adjust the display brightness from 00 to 64 in byte 6.
I have tried to simply do a WriteFile of the data to adjust brightness but no change in device and no sign of data movement on USB analyzer.
I have attached a jpg of the trace Seq 1 - 8 are the initial connection. Seq 9 - 24 are three increase brightness commands. I sure would have thought I could just push that data towards the device and see a brightness change.
Is there something going on that the analyzer is not showing me?
Thanks!
So frustrating!
-
If the device is receiving the data, the problem may be that the host application isn't sending the data in the expected format / report type - assuming it's a HID-class device, the report descriptor will describe the amount of data, its format, and whether it uses Output or Feature reports. For WriteFile, the first data byte sent is the report ID.
I have example HID code using ReadFile and WriteFile here:
http://www.janaxelson.com/hidpage.htm#MyExampleCode
-
"I have tried to simply do a WriteFile" does WriteFile return an error?
-
I get error 6 - ERROR_INVALID_HANDLE. Sure looks like a valid handle to me...
-
Post your code.
-
Actually, found a problem. I had an invalid file handle.
I will post if I can't fix it.
Thanks!!
-
Some concept questions:
File handle questions:
hReadFile = CreateFile(FILE_NAME_ASCIIZ, %GENERIC_READ OR %GENERIC_WRITE, %FILE_SHARE_READ OR %FILE_SHARE_WRITE, BYVAL %NULL, %OPEN_EXISTING, %FILE_FLAG_OVERLAPPED, %NULL)
Using this file handle I can read just fine. And the overlapped part works with WaitForSingleObjest.
Should I use the same file handle to WriteFile? Or should I have a different, not overlapped, handle to write?
hHid = CreateFile(@pz, %GENERIC_READ OR %GENERIC_WRITE, %FILE_SHARE_READ OR %FILE_SHARE_WRITE, BYVAL %NULL, %OPEN_EXISTING, %NULL, %NULL)
What is the exact sequence that one calls the WinAPI to emulate the the transaction shown in the attached jpg sequence 18876 to 18892.
Should I start with HidD_SetOutputReport?
I have been trying to:
RESULT = WriteFile(BYVAL GLOBAL_FILE_HANDLE, WRITE_BUFFER, MY_OutputReportByteLength, BYTES_WRITTEN, MY_OVERLAPPED)
Where (in powerbasic)
WRITE_BUFFER = CHR$(&h03, &H05, &H55, &HAA, &HD1, &H03, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00)
So I guess I have a couple of issues, am I using the correct file handle, am I sending the correct data and am I missing steps...
Thanks
-
Let us know if you have not resolved this (as reported in other recent question).
-
Thanks!
-
"Should I use the same file handle to WriteFile?" I use different ones derived from -
glHidHandle = CreateFile(tIfcDetail.DevicePath, %GENERIC_READ OR %GENERIC_WRITE, _
%FILE_SHARE_READ OR %FILE_SHARE_WRITE, security, %OPEN_EXISTING, 0&, 0&)
glrHidHandle = CreateFile(tIfcDetail.DevicePath, %GENERIC_READ OR %GENERIC_WRITE, _
%FILE_SHARE_READ OR %FILE_SHARE_WRITE, security, %OPEN_EXISTING, %FILE_FLAG_OVERLAPPED, 0&)
I normally use custom microcontroller firmware so I've never seen the need to use reports.