private void ReportReader() { if (!_hid.IsOpen) { _hid.OpenDevice(); } _reading = true; _hid.MonitorDeviceEvents = true; _hid.ReadReport(OnReport, 100); }
public BigRedButtonState?QueryState() { var statusQuery = new HidReport(1) { Data = StatusReport }; var isQueryWritten = device.WriteReport(statusQuery); if (!isQueryWritten) { return(null); } var readReport = device.ReadReport(100); var readData = readReport.Data; if (readReport.ReadStatus != HidDeviceData.ReadStatus.Success) { return(null); } var statusByte = readData[0]; Debug.WriteLine(Convert.ToString(readData[0], 2)); var buttonIsPressed = (statusByte & (1 << 0)) == 0; var lidIsOpen = (statusByte & (1 << 1)) != 0; return(new BigRedButtonState(buttonIsPressed, lidIsOpen)); }
private void DeviceInsert() { OnInserted(); if (!_isActive) { _device.ReadReport(OnReport); //new Thread(ReadThread).Start(); //ThreadPool.QueueUserWorkItem(ReadThread); } }
private static HidReport WriteAndReadReport(IHidDevice device, byte reportId, byte[] data) { var outData = device.CreateReport(); outData.ReportId = reportId; outData.Data = data; device.WriteReport(outData); while (outData.ReadStatus != HidDeviceData.ReadStatus.Success) { Thread.Sleep(1); } var report = device.ReadReport(); return(report); }
public HidConsoleDevice(IHidDevice device) { HidDevice = device; HidDevice.OpenDevice(); ManufacturerString = GetManufacturerString(HidDevice); ProductString = GetProductString(HidDevice); VendorId = (ushort)HidDevice.Attributes.VendorId; ProductId = (ushort)HidDevice.Attributes.ProductId; RevisionBcd = (ushort)HidDevice.Attributes.Version; HidDevice.MonitorDeviceEvents = true; HidDevice.ReadReport(HidDeviceReportEvent); HidDevice.CloseDevice(); }