Hey all, first post on here so I'm sorry if I don't follow the right process of getting help, I'll try to provide as much info as I can.
First, I work for a company that does military applications so I can't give great detail into the use of my software and why I do it the way I do it so try to keep broad-sweeping changes to a minimum because they are of no use to me!
Now, onto the code / application:
I am writing a C#/WPF application that speaks to a device over USB HID protocol and I'm experiencing problems with communication. When I use the kernel32.dll's ReadFile from a validated hidHandle, there's approximately a 1/100 chance that the function just NEVER returns!! Ughhhh!! Right now my workaround is simply threading out the upper level functionality so if it ever locks up it will clear the thread out and try it again.
Where I need help? I am trying to port over the author of this website's generic HID driver + GUI application into my WPF application. I have found that my device does not currently support the Get/SendReport methods (or so it appears, they always fail when I tried them) in the hid.dll (HidD_SetOutputReport()...), so I am going to be using the same WriteFile/ReadFile implementation that my last API used.
Here's as much code/psuedocode as I can possibly provide from my old API that would lock up during ReadFiles. If anyone can find anything wrong with what I was doing or really any insight at all into my situation it would be greatly appreciated, thanks!
Also, the last bit of insight into this project is that the device exclusively talks to the WPF application I am writing so it has no need to check for capabilities and such, it will only respond to the software I write so none of that capability checking stuff is utilized by either end.
My Connect Function (w/ psuedocode)
//
driver.HidGuid();
driver.SetupDiGetClassDevs();
int interface = getDevice; //psuedocode
if(correctDevice){ // psuedocode
SetupInterfaceDetail() // psuedocode
didItWork = driver.CreateFile(devicePath, READ | WRITE, SHARE_READ | SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
}
//
My Read Function - this is the function that gets hung up and i'll comment the line that doesn't return
//
if(driver.HidD_GetPreparsedData(driver.HidHandle, ref ptrToPrepData) != 0)
{
driver.HidP_GetCaps(ptrToPrepData);
return ReadFile(hidHandle, Buffer, InputReportLength, ref numBytesRead, null); // this line does not return sometimes, this is a kernel32.dll import ReadFile in my C# usb driver
}
//
My knowledge of HID USB communication is unfortunately minimal, this project already had its driver api written before I got my hands on it and now I'm trying to clean up the mess left behind so I am still in the learning stage of this HID USB comms stuff.
Any help would be greatly appreciated, let me know if I need to provide more detail or whatever! Thanks!
-bm.nJoi