HidLibrary icon indicating copy to clipboard operation
HidLibrary copied to clipboard

HidDevice.Write(byte[] data) always return false

Open Tweakie opened this issue 13 years ago • 12 comments

I'm using version 3.0.0.0 of your HidLibrary on Windows 7 x64.

I'm seeing the device events from my USB device and can read from it, but every Write fails. Does you have any idea what the reason could be?

Regards, Bart

Tweakie avatar Feb 09 '11 09:02 Tweakie

I'm having the same issue, but I'm not sure whether I'm doing something wrong. The device is connected and open and I can read data fine. I've tried to open it as overlapped and non-overlapped (for both read and write modes), but to no avail.

Tweakie, have you found the issue?

Mike, is this a valid issue or perhaps due to an incorrect use of the library?

I'm also using version 3.0.0.0 on Windows 7 x64.

parautenbach avatar May 16 '12 09:05 parautenbach

Some more info: I've created a GIT clone and upon debugging the test app included in the source, I see it's the native WriteFile method that returns false, but that's about it. Going deeper requires an understanding of the kernel and the debugger cannot provide me with more info.

parautenbach avatar May 16 '12 10:05 parautenbach

I think I didn't solve the issue, but I'm not sure . It was more than a year ago and I didn't have access anymore to the code where I used the library.

On Wed, May 16, 2012 at 12:19 PM, parautenbach < [email protected]

wrote:

Some more info: I've created a GIT clone and upon debugging the test app included in the source, I see it's the native WriteFile method that returns false, but that's about it. Going deeper requires an understanding of the kernel and the debugger cannot provide me with more info.


Reply to this email directly or view it on GitHub: https://github.com/mikeobrien/HidLibrary/issues/6#issuecomment-5737691

Tweakie avatar May 16 '12 11:05 Tweakie

Thanks, Tweakie.

parautenbach avatar May 16 '12 11:05 parautenbach

I solved my problem: I was writing my data directly from a byte buffer, instead of first creating a report. As a novice, I didn't quite understand input and output reports.

parautenbach avatar May 17 '12 17:05 parautenbach

@parautenbach can you help me? I'v the same error in Win8 x64

hram avatar Feb 06 '14 08:02 hram

@hram: It's a shot in the dark without knowing what type of device you're communicating with, but remember that USB devices are block devices and that you have to write data using the supported block size (chunks). You get it from the device capabilities. Also make a distinction between raw writes and reports. Disclaimer: I'm no expert at USB devices or communication, but do have some background.

parautenbach avatar Feb 06 '14 08:02 parautenbach

@parautenbach I have 2 different libraries. One of them works fine but i realy like source code of this one. I was trying Write(byte[] data) and WriteReport(HidReport report, WriteCallback callback) and always result is false. In my case Capabilities.OutputReportByteLength == 65. Whay? I think USB buffer have to be 64 bytes.

hram avatar Feb 06 '14 08:02 hram

Again, you're providing very vague information. What is the other library that works? Isn't it more important to stick what works? All I can say, is that a report length of 65 sounds strange, as it's not a power of 2. But, it sounds like your device wants 65 bytes and you're giving it 64. Without any example code it's impossible to say. You could also compare the binary (hex) raw data created by each library.

You could refer here for some example code : https://github.com/parautenbach/Build-Lights-Server-and-Client/blob/master/src/WhatsThatLight.Ci.Tools.BuildLights.Client/LightsDeviceController.cs

parautenbach avatar Feb 06 '14 08:02 parautenbach

I am using this library in https://github.com/eried/PrimeComm and my device also returns 65, I have checked with an usb sniffer and it seems the "first" byte is the index%0xFF of the report (I can confirm that the Write works properly).

eried avatar Feb 06 '14 16:02 eried

Thanks boss!!!!!!

for to gave rid from my issue

SaddamBInSyed avatar Dec 04 '14 13:12 SaddamBInSyed

one thing some of the card reader device not usually sending the data via data line rather it sending in Control line so in that case,

Don not use WriteFile() funtion to send the data in HID Instead of this you Must use HidD_SetFeature() from hid.dll

Thanks Saddam

SaddamBInSyed avatar Dec 04 '14 13:12 SaddamBInSyed