Ejemplo n.º 1
0
        protected override DeviceStream OpenDeviceDirectly(OpenConfiguration openConfig)
        {
            RequiresGetInfo();

            var stream = new LinuxHidStream(this);

            try { stream.Init(_path); return(stream); }
            catch { stream.Close(); throw; }
        }
Ejemplo n.º 2
0
        bool TryParseReportDescriptor(out Reports.ReportDescriptor parser, out byte[] reportDescriptor)
        {
            parser = null; reportDescriptor = null;

            int handle;

            try { handle = LinuxHidStream.DeviceHandleFromPath(_path, this, NativeMethods.oflag.NONBLOCK); }
            catch (FileNotFoundException) { throw DeviceException.CreateIOException(this, "Failed to read report descriptor."); }

            try
            {
                uint descsize;
                if (NativeMethods.ioctl(handle, NativeMethods.HIDIOCGRDESCSIZE, out descsize) < 0)
                {
                    return(false);
                }
                if (descsize > NativeMethods.HID_MAX_DESCRIPTOR_SIZE)
                {
                    return(false);
                }

                var desc = new NativeMethods.hidraw_report_descriptor()
                {
                    size = descsize
                };
                if (NativeMethods.ioctl(handle, NativeMethods.HIDIOCGRDESC, ref desc) < 0)
                {
                    return(false);
                }

                Array.Resize(ref desc.value, (int)descsize);
                parser           = new Reports.ReportDescriptor(desc.value);
                reportDescriptor = desc.value; return(true);
            }
            finally
            {
                NativeMethods.retry(() => NativeMethods.close(handle));
            }
        }