1

Topic: HidSharp stream.Write throws an exception

Just started using HidSharp, and love the elegant simplicity of finding devices.

I can succesfully find my device, Open it and attach it to a HidStream
If I do Read's on it as in the demo programs, they timeout as expected because my device will not return any data until it has recd a command.

So when I try to send it a command using stream.Write  it always ends up with thisException:
  An unhandled exception of type 'System.IO.IOException' occurred in HidSharp.dll
  Additional information: Operation failed early.

Its simple enough that I cannot see what I am doing wrong.  Running on Windows10 and VS2013.  I can duplicate the behavior from HidSharp.Test in CS.  And also from my own app in CPP using HidSharp.dll as a reference.

After the stream is open I do
                    var bytesout = System.Text.Encoding.ASCII.GetBytes("CFGR0");
                    stream.Write(bytesout);

More detail below...
Would appreciate any help figuring this out.
Thanks
Daraius


If I break in the debugger it ends up in
<NativeMethods.cs>
        public unsafe static void OverlappedOperation(IntPtr ioHandle,
            IntPtr eventHandle, int eventTimeout, IntPtr closeEventHandle,
            bool overlapResult,
            NativeOverlapped* overlapped, out uint bytesTransferred)
        {
            bool closed = false;

            if (!overlapResult)
            {
                int win32Error = Marshal.GetLastWin32Error();
                if (win32Error != NativeMethods.ERROR_IO_PENDING)
                {
                    throw new IOException("Operation failed early.", new Win32Exception());
                }

                IntPtr* handles = stackalloc IntPtr[2];

2

Re: HidSharp stream.Write throws an exception

What Report ID are you trying to write to? Packets need to include that as the first byte, or 0 if there is no Report ID.