static void Main() { _device = HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault(); if (_device != null) { _device.OpenDevice(); _device.Inserted += DeviceAttachedHandler; _device.Removed += DeviceRemovedHandler; _device.MonitorDeviceEvents = true; _device.ReadReport(OnReport); Console.WriteLine("Reader found, press any key to exit."); Console.ReadKey(); _device.CloseDevice(); } else { Console.WriteLine("Could not find reader."); Console.ReadKey(); } }
public HidChannel(int vid, int pid) { dev = HidDevices.Enumerate(vid, pid).FirstOrDefault(); //usb.OnSpecifiedDeviceArrived += usb_OnSpecifiedDeviceArrived; //usb.OnDataRecieved += usb_OnDataRecieved; }
public bool OpenDevice() { var devices = HidDevices.Enumerate(VendorId); if (devices != null && devices.Any()) { Device = devices.First(); if (Device != null) { Device.OpenDevice(); Device.Inserted += () => { DeviceAttached(); Device.ReadReport(OnReportReceived); }; Device.Removed += DeviceRemoved; Device.MonitorDeviceEvents = true; return true; } } return false; }
public HidDeviceEventMonitor(HidDevice device) { this.device = device; monitor = new BackgroundWorker<bool>(); monitor.Updated += new EventHandler<EventArgs<bool>>(monitor_Updated); monitor.DoWork += new System.ComponentModel.DoWorkEventHandler(monitor_DoWork); }
public static IEnumerable<HidDevice> Enumerate(int vendorId) { foreach (var path in EnumerateHidDevices()) { var device = new HidDevice(path); if (device.Attributes.VendorId == vendorId) yield return device; } }
private void Devices_SelectedIndexChanged(object sender, EventArgs e) { if ((_selectedDevice != null)) _selectedDevice.CloseDevice(); _selectedDevice = _deviceList[Devices.SelectedIndex]; _selectedDevice.OpenDevice(); _selectedDevice.MonitorDeviceEvents = true; _selectedDevice.Inserted += Device_Inserted; _selectedDevice.Removed += Device_Removed; }
public bool OpenDevice(HidDevice adevice) { if (adevice != null) { this.device = adevice; return OpenCurrentDevice(); } return false; }
public static IEnumerable<HidDevice> Enumerate(int vendorId, params int[] productIds) { List<int> pids = new List<int>(productIds); foreach (var path in EnumerateHidDevices()) { var device = new HidDevice(path); if (device.Attributes.VendorId == vendorId && pids.Contains(device.Attributes.ProductId)) yield return device; } }
/// <summary> /// Checks the Hid Devices looking for the first calculator /// </summary> public void CheckForChanges() { foreach (var d in HidDevices.Enumerate(1008, new[] { 1089 })) { _calculator = d; IsConnected = true; return; } IsConnected = false; }
public Scanner(HidDevice hidDevice) { _scanner = hidDevice; _scanner.Inserted += ScannerInserted; _scanner.Removed += ScannerRemoved; if (!_scanner.IsOpen) _scanner.OpenDevice(); _scanner.MonitorDeviceEvents = true; BeginReadReport(); }
public bool Connect(HidDevice device) { scale = device; int waitTries = 0; scale.OpenDevice(); while (!scale.IsConnected && waitTries < 10) { Thread.Sleep(50); waitTries++; } return scale.IsConnected; }
public BlinkStick() { HidDevice[] devices = HidDevices.Enumerate(VendorID, ProductID).ToArray(); if (!devices.Any()) { throw new IOException("No BlinkStick found"); } m_stick = devices.First(); m_blinkEndTimer.Elapsed += OnBlinkEndTimerElapsed; }
private bool IsDeviceWithinBlink1mk2Range(HidDevice device) { byte[] serialBytes; var readSerial = device.ReadSerialNumber(out serialBytes); if (!readSerial) { return false; } return serialBytes[0] == 0x32; }
public MainWindow() { InitializeComponent(); device = HidDevices.Enumerate(vid, pid).FirstOrDefault(); try { device.OpenDevice(); } catch { valueSlider.IsEnabled = false; } }
public WeatherStation(HidDevice hidDevice) { _weatherStation = hidDevice; _weatherStation.Inserted += _weatherStation_Inserted; _weatherStation.Removed += _weatherStation_Removed; if (!_weatherStation.IsOpen) _weatherStation.OpenDevice(); _weatherStation.MonitorDeviceEvents = true; _history = new List<HistoryData>(); }
public bool Connect(HidDevice device) { scale = device; int waitTries = 0; scale.OpenDevice(); // sometimes the scale is not ready immedietly after // Open() so wait till its ready while (!scale.IsConnected && waitTries < 10) { Thread.Sleep(50); waitTries++; } return scale.IsConnected; }
public Mate(HidDevice d, MidiDevice md, MidiControl mc, MidiChannel mchan) { mateManager = new MateManager(); mateManager.OpenDevice(d); mateManager.ButtonDown += new EventHandler<PowerMateEventArgs>(ButtonDown); mateManager.ButtonUp += new EventHandler<PowerMateEventArgs>(ButtonUp); Dark(); counter++; id = counter; Name = "Powermate " + id; SelectedDevice = md; SelectedControl = mc; SelectedChannel = mchan; }
public void InitHID() { HidDevice[] devices; devices = GetDevices(); foreach (HidDevice d in devices) { if (d.Capabilities.InputReportByteLength >= 40) { WriteLog("Path: " + d.DevicePath); WriteLog("Desc: " + d.Description); WriteLog("Input Report Size: " + d.Capabilities.InputReportByteLength); _device = d; break; } } _running = true; }
private bool Connect() { _device = HidDevices.Enumerate(VendorId, ProductId, 0xFFAB, 0x0200).FirstOrDefault(); if (_device != null) { _device.OpenDevice(); _device.Inserted += DeviceAttachedHandler; _device.Removed += DeviceRemovedHandler; _device.MonitorDeviceEvents = true; _isAttached = true; PrintOutputLine("rawhid device found"); } else { PrintOutputLine("no rawhid found"); _isAttached = false; } return _isAttached; }
/// <summary> /// Attempts to connect to a PowerMate device. /// /// After a successful connection, a DeviceAttached event will normally be sent. /// </summary> /// <returns>True if a PowerMate device is connected, False otherwise.</returns> public bool OpenDevice() { device = HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault(); if (device != null) { connectedToDriver = true; device.OpenDevice(); device.Inserted += DeviceAttachedHandler; device.Removed += DeviceRemovedHandler; device.MonitorDeviceEvents = true; device.ReadReport(OnReport); return true; } return false; }
public OpenLauncher() { initCommands(); // Enumerate the devices deviceList = HidDevices.Enumerate(0x2123, 0x1010); if (deviceList.Count() < 1) { throw new Exception("Could not find device"); } DevicePresent = true; dev1 = deviceList.FirstOrDefault(); dev1.OpenDevice(); dev1.Inserted += DeviceAttachedHandler; dev1.Removed += DeviceRemovedHandler; dev1.MonitorDeviceEvents = true; //dev1.CloseDevice(); }
public DrumKitController(HidDevice device) { foreach (var productId in ProductIds) { if (device == null) { _device = HidDevices.Enumerate(VendorId, productId).FirstOrDefault(); } else { IEnumerable<HidDevice> devices = HidDevices.Enumerate(VendorId, productId);//.Where(x => x.DevicePath != device.DevicePath).FirstOrDefault(); _device = devices.Where(d => d.DevicePath != device.DevicePath).FirstOrDefault(); } if (_device == null) continue; _currentProductId = productId; _device.OpenDevice(); _device.Inserted += DeviceAttachedHandler; _device.Removed += DeviceRemovedHandler; _device.MonitorDeviceEvents = true; _device.ReadReport(OnReport); break; } if (_device != null) { //Console.WriteLine("Gamepad found, press any key to exit."); _device.CloseDevice(); } else { //Console.WriteLine("Could not find a gamepad."); } }
/// <summary> /// After a successful connection, a DeviceAttached event will normally be sent. /// </summary> /// <returns>True if a device is connected, False otherwise.</returns> public bool Connect() { //TODO: introduce a way to handle multiple devices throughout driver Devices = HidDevices.Enumerate(VendorId, ProductId); _device = Devices.FirstOrDefault(); if (_device != null) { _connectedToDriver = true; _device.OpenDevice(); _device.Inserted += DeviceAttachedHandler; _device.Removed += DeviceRemovedHandler; _device.MonitorDeviceEvents = true; _device.ReadReport(OnReport); return true; } return false; }
public HidDeviceEventMonitor(HidDevice device) { _device = device; }
private static bool WriteData(HidDevice device, byte[] data) { bool wroteData = device.Write(data); if (!wroteData) Console.WriteLine("Failed to write data"); return wroteData; }
// Device cannot accurately display 255 different levels (hardware limitation?) // Yellow and Orange look the same public MailNotifier() { var devices = HidLibrary.HidDevices.Enumerate(0x1D34, 0x0004); foreach (var device in devices) { System.Diagnostics.Debug.WriteLine("Found Dream Cheeky Mail Notifier Device"); device.OpenDevice(); byte[] init1 = { 0x00, 0x1f, 0x02, 0x00, 0x2e, 0x00, 0x00, 0x2b, 0x03 }; byte[] init2 = { 0x00, 0x00, 0x02, 0x00, 0x2e, 0x00, 0x00, 0x2b, 0x04 }; byte[] init3 = { 0x00, 0x00, 0x02, 0x00, 0x2e, 0x00, 0x00, 0x2b, 0x05 }; WriteData(device, init1); WriteData(device, init2); m_device = device; } }
private void RefreshDevices() { _deviceList = HidDevices.Enumerate(0x0801, 0x0002).ToArray(); //_deviceList = HidDevices.Enumerate(0x536, 0x207, 0x1c7).ToArray(); Devices.DisplayMember = "Description"; Devices.DataSource = _deviceList; if (_deviceList.Length > 0) _selectedDevice = _deviceList[0]; }
static uint GetSerialNumber(HidDevice device) { byte[] sn; device.ReadSerialNumber(out sn); string snString = System.Text.Encoding.Unicode.GetString(sn).TrimEnd("\0".ToArray()); return (Convert.ToUInt32(snString, 16) * 10); }
static void Main() { foreach (var productId in ProductIds) { _device = HidDevices.Enumerate(VendorId, productId).FirstOrDefault(); if (_device == null) continue; _currentProductId = productId; _device.OpenDevice(); _device.Inserted += DeviceAttachedHandler; _device.Removed += DeviceRemovedHandler; _device.MonitorDeviceEvents = true; _device.ReadReport(OnReport); break; } if (_device != null) { Console.WriteLine("Gamepad found, press any key to exit."); Console.ReadKey(); _device.CloseDevice(); } else { Console.WriteLine("Could not find a gamepad."); Console.ReadKey(); } }
protected HIDTransportBase(HidDevice device, UsageSpecification[] acceptedUsageSpecifications) { if(!device.IsOpen) device.OpenDevice(); _Device = device; _DevicePath = device.DevicePath; _VendorProductIds = new VendorProductIds(device.Attributes.VendorId, device.Attributes.ProductId); _AcceptedUsageSpecifications = acceptedUsageSpecifications; ReadTimeout = TimeSpan.FromMilliseconds(DEFAULT_TIMEOUT); }
/// <summary> /// Create a new Win7 forwaderer. /// </summary> /// <param name="dArgs"></param> public Win7Forwarder(Dictionary<String, String> dArgs) { // If the HID device is not loaded. if (pDevice == null) { // Access the HID device driver. pDevice = HidDevices.Enumerate(0xdddd, 0x0001).FirstOrDefault(); if (pDevice == null) throw new InvalidOperationException("Touchscreen HID driver was not found. Personal/non-commercial projects can use the compatible UniSoftHID driver."); // Open the HID device. try { pDevice.OpenDevice(DeviceMode.Overlapped, DeviceMode.NonOverlapped, ShareMode.ShareRead | ShareMode.ShareWrite); } catch (Exception e) { pDevice = null; throw e; } } // Increment device count. iDeviceReferences++; // Pick a screen to inject onto. String sScreenIndex = null; if (!dArgs.TryGetValue("screen", out sScreenIndex)) sScreenIndex = "0"; if (!int.TryParse(sScreenIndex, out iScreenIndex)) throw new ArgumentException("Cannot accept non-numeric screen index."); if (iScreenIndex < 0 || iScreenIndex >= lScreens.Count) throw new ArgumentException("Screen index out of range."); }