Topic: HidSharp write: 'Operation failed early: The parameter is incorrect'
Hello,
I have a USB scanner for bar codes/QR codes/MRZ.
I have a user manual from the manufacturer, which contains a set of QR codes that allow me to configure the device.
For example by scanning the following values:
$>:S01010F.<$ (Enter Setup)
$>: S0F0516.<$ (USB HID POS)
$>:S01000F.<$ (Exit Setup)
I was able to switch the device to "USB HID POS" mode. (default mode being "USB HID-KBW" in which the scanner behaves like a keyboard)
In this mode I am able to read scanned data using the HidSharp library.
However I also need to be able to change the settings of the device programmatically. But when I call stream.Write, I always get the following exception:
System.IO.IOException: 'Operation failed early: The parameter is incorrect'
Stack trace:
at HidSharp.Platform.Windows.NativeMethods.OverlappedOperation(IntPtr ioHandle, IntPtr eventHandle, Int32 eventTimeout, IntPtr closeEventHandle, Boolean overlapResult, NativeOverlapped* overlapped, UInt32& bytesTransferred)
There's an inner exception that just says Win32Exception: 'The parameter is incorrect' (no stack trace)
Info about the device:
// hdev.ToString() + " | " + hdev.DevicePath
Linux 3.10.14 with dwc2-gadget hidpos 00000000 (VID 4619, PID 33287, version 3.10) | \\?\hid#vid_120b&pid_8207#7&52366e0&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
(the device itself has "Linux" in the name, I'm currently running Windows 10)
The following is an enumeration over the device's Reports:
Max Lengths: Input 64, Output 64, Feature 0
Serial Ports:
1 device items found.
Usage: 8C0001 9175041
Input: ReportID=2, Length=64, Items=1
63 Elements x 8 Bits, Units: None, Expected Usage Type: 0, Flags: Variable, BufferedBytes, Usages: 8C00FE 9175294
Output: ReportID=4, Length=64, Items=1
63 Elements x 8 Bits, Units: None, Expected Usage Type: 0, Flags: Variable, Relative, Nonlinear, Volatile, Usages: 8C0000 9175040
What I'm trying to do:
Assuming the device supports receiving setup commands, and that these are the same as the commands from the QR codes, I've been trying to send the following commands to the device (one at a time):
01010F (Enter Setup)
0C0814 (Set external illumination to "Always on")
01000F (Exit Setup)
NOTE: I've tried sending it in the format $>:S01010F.<$ and S01010F, but I suspect those are just some tags telling the QR parser it's a command, and the actual command is the 6 digit hex string.
I've tried creating the input buffer diretly:
var enterSetupBuffer = Encoding.ASCII.GetBytes("01010F");
I've tried creating a byte array of size 64 and setting the first few bytes in the array:
var someBuffer = new byte[64];
someBuffer[0] = 0x01;
someBuffer[1] = 0x01;
someBuffer[2] = 0x0F;
(and some variations on this)
no matter what I do, I get the same error: Operation failed early: The parameter is incorrect.
Some more details: I try to write using the HidStream.Write(buffer). I attempt the write before I start reading from the device. stream.CanWrite is returning true.
As you've probably guessed, I'm not good with hardware. I'm primarily a business application developer. All my attempts so far have been pretty much guesswork. I don't even know if it's the device rejecting my attempts at communication, or if there's something else I don't even know about tripping me up before the data is even sent to the device.
Any help would be greatly appreciated.