I recently acquired an off the shelf Weather Station that is capable to connecting to a PC via a USB Cable.
Being my first foray into USB, I’ve had to go back & learn the protocols, combined with using a logic/protocol Analyzer to reconstruct what was happening on the USB lines.
Using the /codeshare/entry/115 & updating it to work with 4.3, I was able to query the endpoint, and get the relevant attributes. The problem arose when I tried to get the actual data dump from the Weather Station, even using the EXACT SAME protocol string that their Software on the PC was using.
I get the message "An unhandled exception of type 'System.Exception' occurred in GHI.Usb.dll"
When called from this
```cs]public void SendSetupPacket(byte requestType, byte request, ushort value, ushort index, byte[
data, int dataOffset, int dataCount)
{
base.CheckObjectState(true);
this.NativeSendSetupPacket(requestType, request, value, index, data, dataOffset, dataCount);
}
So, using the protocol analyzer, I deconstructed where the error actually occurs, and found it happens if you make the buffer larger than the data coming back, it throws the exception. (Which is exactly what their software was doing, setting the buffer larger!!).
My problem is, If I don’t know how long the string is, on a custom “Unknown” device, sort of like you may not know the size of a picture on a camera, (and I noticed he set the buffer to maximum packet size), they may be related, as when I tried to create a pipe, and get the data, it froze the exact same way on this line:
In the short term,, because I have a fairly narrow range of possible returns,, I'm just encasing it all in a Try / Catch routine,, and will need to work out a way to verify I'm getting all the data available,, (for example, when it downloads historic data,, there may be 5 records,, or 50)..
I was just wondering if I was missing something...
Thanks
Michael.