1

Topic: LinuxHidStream GetFeature/SetFeature

Hi,

I was looking to use your library to control a Blink(1) device.

It works fine in windows but on a raspberry pi (the real target device) it won't work because GetFeature & SetFeature are not implemented.

Can you please tell me if this is something that is being looked at or if you can provide some pointers as to how I might add the functionality.

Thanks,
Barry.

2

Re: LinuxHidStream GetFeature/SetFeature

I was able to get this working after coming across this c code:
github.com/signal11/hidapi/blob/master/linux/hid.c

The changes I made were:

NativeMethods.cs

        public static int HIDIOCSFEATURE(int len)
        {
            return IOC(IOC_WRITE | IOC_READ, (byte)'H', 6, len);
        }

        public static int HIDIOCGFEATURE(int len)
        {
            return IOC(IOC_WRITE | IOC_READ, (byte)'H', 7, len);
        }

        [DllImport(libc, SetLastError = true)]
        public static extern int ioctl(int filedes, int command, IntPtr data);

LinuxHidStream.cs

        public override void GetFeature (byte[] buffer, int offset, int count)
        {
            byte[] data = new byte[count];
            Array.Copy (buffer, offset, data, 0, count);
            GetFeatureNative(data);
            Array.Copy (data, 0, buffer, offset, count);
        }

        unsafe void GetFeatureNative(byte[] data)
        {
            fixed (byte* ptr = data) 
            {
                NativeMethods.ioctl (_handle, NativeMethods.HIDIOCGFEATURE (data.Length), (IntPtr)ptr);
            }
        }

        public override void SetFeature(byte[] buffer, int offset, int count)
        {
            byte[] data = new byte[count];
            Array.Copy (buffer, offset, data, 0, count);
            SetFeatureNative(data);
        }

        unsafe void SetFeatureNative(byte[] data)
        {
            fixed (byte* ptr = data) 
            {
                NativeMethods.ioctl (_handle, NativeMethods.HIDIOCSFEATURE (data.Length), (IntPtr)ptr);
            }
        }

Hopefully it will be of use to somebody else

3

Re: LinuxHidStream GetFeature/SetFeature

Hello bdunne,

Hmm. The version of HidSharp I have here already has GetFeature/SetFeature on Linux. What version are you using? (Or is the current implementation broken?)

Thanks!

James

4

Re: LinuxHidStream GetFeature/SetFeature

Both methods in LinuxHidStream.cs in v1.5 downloaded from zer7.com/software/hidsharp contain this line:

throw new NotSupportedException(); // TODO