1

Topic: LinuxHidStream GetFeature buffer offset

I am trying to use HidSharp on Ubuntu 18.04 to interface with a blink(1) mk2 device.

SetFeature works great, but I seem to be running into an issue with GetFeature, which I believe to be with the library.

Whenever I try to read data from the device, all bytes after the report id appears to be shifted by one.

eg, reading the color back from the device, I expect back the following sequence:

ReportId, 'r', R, G, B, 0, 0, 0

But instead I get

ReportId, 0, 'r', R, G, B, 0, 0

Other reads are similarly suffering from an added zero byte after the report id.

Looking at the source for the LinuxHidStream class, in the GetFeature method, the call to ioctl passes numPtr + offset + 1 as the value argument. While I admit to not fully understand that low level call, I was wondering if perhaps that value should not have one added to it, as this amendment might already be taken into account by the system call.

Is anyone else experiencing a similar issue? Or is it just me?

My next step is to remove the NuGet reference, clone the source, make the change, and see if it solves the problem. I'll report back with my findings.

2

Re: LinuxHidStream GetFeature buffer offset

I have amended the fixed block from the LinuxHidStream.GetFeature from:

buffer[offset + 1] = reportID;
int bytes = NativeMethods.ioctl(_handle, NativeMethods.HIDIOCGFEATURE(count - 1), (IntPtr)(ptr + offset + 1));
if (bytes < 0) { throw new IOException("GetFeature failed."); }
Array.Clear(buffer, 1 + bytes, count - (1 + bytes));

to

int bytes = NativeMethods.ioctl(_handle, NativeMethods.HIDIOCGFEATURE(count), (IntPtr)(ptr + offset));
if (bytes < 0) { throw new IOException("GetFeature failed."); }
if(buffer.Length < offset + bytes)
    Array.Clear(buffer, offset + bytes, buffer.Length - offset - bytes);

I am not sure why the whole operation was shifted by one in the first place, but reading over the original buffer, without an offset of 1, seems to work for my use case.

3 (edited by johnbizios 2020-02-11 13:11:36)

Re: LinuxHidStream GetFeature buffer offset

Had the same issue...see my post on Ubuntu and Byte Ordering and scroll to the last message....https://forum.zer7.com/topic/10140/

4

Re: LinuxHidStream GetFeature buffer offset

Haha looks like we've implemented the exact same fix, and are both equally puzzled by it.
Great minds think alike.