Ejemplo n.º 1
0
        internal HidDevice(HidControl control, string devicePath)
        {
            controller = control;

            dev = new DeviceAccess(devicePath);

            if (dev.OpenDeviceForIoctl())
            {
                NativeApi.HidD_GetAttributes(dev.Handle, ref Attributes);

                using (HidPreparsedData preparsedData = new HidPreparsedData(dev.Handle))
                {
                    NativeApi.HidP_GetCaps(preparsedData.Handle, ref Capabilities);
                }

                if (dev.OpenDeviceForRead())
                {
                    ReadThread = new DeviceReadThread(new DeviceAccess(devicePath), new ReceivedReportDelegate(InputPipeReportHandler));
                }
                else
                {
                    ReadThread = null;
                }
            }
            else
            {
                throw new Exception("Unable to access device!");
            }
        }
Ejemplo n.º 2
0
        public HidReport ReadInputReport()
        {
            byte[]    buf    = new byte[GetReportLength(HidReportType.Input)];
            HidReport report = new HidInReport(buf);

            if (dev.OpenDeviceForRead())
            {
                if (report.Length == GetReportLength(HidReportType.Input))
                {
                    if (!NativeApi.HidD_GetInputReport(dev.Handle, report.Bytes, report.Length))
                    {
                        throw new Exception("GetInputReport: " + Marshal.GetLastWin32Error().ToString());
                    }
                }
            }
            else
            {
                throw new Exception("Unable to open device for Read");
            }

            return(report);
        }