private bool SetupDevice(HidDevice device, out HidStream stream, out HidDeviceInputReceiver receiver) { stream = null; receiver = null; if (device == null) { return(false); } try { if (!device.TryOpen(out stream)) { return(false); } var descriptor = device.GetReportDescriptor(); receiver = descriptor.CreateHidDeviceInputReceiver(); receiver.Received += OnReceiverReceived; receiver.Start(stream); } catch (Exception e) { Log($"Exception while setting up device occured: {e}"); return(false); } return(receiver.IsRunning); }
/// <summary> /// Begin communication with moRFeus /// </summary> private void ConfigDevice() { // Report stream opened if (moRFeusDevice.TryOpen(out moRFeusStream)) { moRFeusStream.ReadTimeout = Timeout.Infinite; // HIDSharp setup reportBuffer = new byte[moRFeusDevice.GetMaxInputReportLength()]; ReportDescriptor reportDescriptor = moRFeusDevice.GetReportDescriptor(); reportReceiver = reportDescriptor.CreateHidDeviceInputReceiver(); // Receive event handling //reportReceiver.Received += ReportReceived; reportReceiver.Start(moRFeusStream); // Disconnect event handling moRFeusStream.Closed += new EventHandler(Disconnected); // Indicate successful connection Tools.Debug("Connected to moRFeus"); Program.MainClass.StatusMessage = "Connected to moRFeus"; Program.MainClass.EnableUI(); moRFeusOpen = true; // Initial polling of device values Task.Delay(10).ContinueWith(t => Program.MainClass.PollDevice()); } }
public void Start() { if (_digitizer.TryOpen(out _hidStream)) { _hidDeviceInputReceiver = _reportDescr.CreateHidDeviceInputReceiver(); _hiddeviceInputParser = _reportDescr.DeviceItems[0].CreateDeviceItemInputParser(); _hidDeviceInputReceiver.Received += OnDigitizerInputReceived; _hidDeviceInputReceiver.Start(_hidStream); } else { throw new Exception("Failed to open iBridge HID digitizer"); } }
public override void CommOpen(Bsl430NetDevice device) { try { Bsl430NetDevice _device = device; if (device == null) { _device = DefaultDevice; } if (_device == null || _device.Name == "") { throw new Bsl430NetException(461); } if (!devices.ContainsKey(_device.Name.ToLower())) { Status stat = Scan <USB_HID_Device>(out _); if (!stat.OK) { throw new Bsl430NetException(stat.Error); } } if (!devices.TryGetValue(_device.Name.ToLower(), out USB_HID_Device dev)) { throw new Bsl430NetException(462); } DeviceList.Local.GetHidDeviceOrNull(dev.Vid, dev.Pid)?.TryOpen(out usb); if (usb == null) { throw new Bsl430NetException(610); } else { max_output_len = usb.Device.GetMaxOutputReportLength(); max_input_len = usb.Device.GetMaxInputReportLength(); usb.ReadTimeout = Timeout.Infinite; reportDescriptor = usb.Device.GetReportDescriptor(); inputReceiver = reportDescriptor.CreateHidDeviceInputReceiver(); inputReceiver.Start(usb); } } catch (Exception ex) { throw new Bsl430NetException(611, ex); } }
public RawInputDevice(HidDevice device, ReportDescriptor reportDescriptor, DeviceItem deviceItem, HidStream hidStream, string uniqueId) { this.device = device; inputReportBuffer = new byte[device.GetMaxInputReportLength()]; inputReceiver = reportDescriptor.CreateHidDeviceInputReceiver(); inputParser = deviceItem.CreateDeviceItemInputParser(); inputReceiver.Start(hidStream); DisplayName = device.GetProductName(); UniqueId = uniqueId; InterfacePath = device.DevicePath; HardwareID = IdHelper.GetHardwareId(InterfacePath); inputChangedEventArgs = new DeviceInputChangedEventArgs(this); sources = reportDescriptor.InputReports.SelectMany(ir => ir.DataItems) .SelectMany(di => di.Usages.GetAllValues()) .Select(u => (Usage)u) .SelectMany(u => RawInputSource.FromUsage(this, u)) .ToArray(); readThreadContext = ThreadCreator.CreateLoop($"{DisplayName} RawInput reader", ReadLoop, 1).Start(); }