MFD(int id) { this.Id = id; var loader = new HidDeviceLoader(); if (id == 1) { _device = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD1_PRODUCT_ID).First(); if (_device == null) { throw new Exception("MFD1 Device not found"); } } else if (id == 2) { _device = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD2_PRODUCT_ID).First(); if (_device == null) { throw new Exception("MFD2 Device not found"); } } else { throw new InvalidOperationException("Invalid MFD ID selected"); } }
static void Main(string[] args) { var loader = new HidDeviceLoader(); //var devices = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD_PRODUCT_ID); var devices = loader.GetDevices(THRUSTMASTER_VENDOR_ID); var deviceMFD1 = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD1_PRODUCT_ID).First(); var deviceMFD2 = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD2_PRODUCT_ID).First(); if (deviceMFD1 != null) { byte brightness = 0x09; byte ledStatus = 0; var device = deviceMFD1; SetBrightness(brightness, device); brightness = GetBrightness(device); //SetLEDStatus(device, false, true); // left light off, right light on //SetLEDStatus(device, true, false); // left light on, right light on //SetLEDStatus(device, true, true); // left light on, right light on SetLEDStatus(device, false, false); // left light on, right light on ledStatus = GetLEDStatus(device); } Console.Write("Devices: "); Console.WriteLine(devices.Count()); Console.WriteLine("Done!"); }
public static IEnumerable <MuniaConfigInterface> GetMuniaConfigInterfaces() { var ldr = new HidDeviceLoader(); var candidates = ldr.GetDevices(0x04d8, 0x0058) .Union(ldr.GetDevices(0x1209)); foreach (HidDevice dev in candidates.Where(device => device.ProductName == "NinHID CFG" || device.GetMaxInputReportLength() == device.GetMaxOutputReportLength() && device.GetMaxOutputReportLength() == 9)) { yield return(new MuniaConfigInterface(dev)); } }
public static IEnumerable <MuniaController> ListDevices() { var ldr = new HidDeviceLoader(); // MUNIA devices with 0x1209 VID foreach (var device in ldr.GetDevices(0x1209)) { if (device.ProductName == "NinHID NGC") { yield return(new MuniaNgc(device)); } else if (device.ProductName == "NinHID N64") { yield return(new MuniaN64(device)); } else if (device.ProductName == "NinHID SNES") { yield return(new MuniaSnes(device)); } } // MUSIA devices foreach (var device in ldr.GetDevices(0x1209, 0x8844)) { if (device.ProductName == "MUSIA PS2 controller") { yield return(new MusiaPS2(device)); } } // legacy VID/PID combo from microchip foreach (var device in ldr.GetDevices(0x04d8, 0x0058)) { if (device.ProductName == "NinHID NGC" || device.GetMaxInputReportLength() == 9 && device.GetMaxOutputReportLength() == 0) { yield return(new MuniaNgc(device)); } else if (device.ProductName == "NinHID N64" || device.GetMaxInputReportLength() == 5) { yield return(new MuniaN64(device)); } else if (device.ProductName == "NinHID SNES" || device.GetMaxInputReportLength() == 3) { yield return(new MuniaSnes(device)); } } }
public GamepadManager() { _hidDeviceLoader = new HidDeviceLoader(); FoundDevices = new ObservableCollection <HidDeviceRepresentation>(); SelectedDevice = JsonConvert.DeserializeObject <HidDeviceRepresentation>(Settings.Default.SelectedHidDevice); if (SelectedDevice != null && !FoundDevices.Contains(SelectedDevice)) { FoundDevices.Add(SelectedDevice); } _currentDeviceUpdateThread = new Thread(() => { while (true) { var hidDevices = _hidDeviceLoader.GetDevices(); var currentDevices = hidDevices.Select(hidDevice => new HidDeviceRepresentation(hidDevice)).ToList(); foreach (var newDevice in currentDevices.Where(device => !FoundDevices.Contains(device))) { Application.Current.Dispatcher.Invoke(() => FoundDevices.Add(newDevice)); } Thread.Sleep(TimeSpan.FromSeconds(10)); } }); _currentDeviceUpdateThread.Start(); }
/// <summary> /// Initializes communication with the DTS Card /// </summary> /// <returns>True if update is sucessful, false if there was a problem.</returns> public bool initialize() { if (_device == null) { dispose(); } HidDeviceLoader deviceLoader = new HidDeviceLoader(); foreach (HidDevice device in deviceLoader.GetDevices(0x04d8, 0xf64e)) { if (device.SerialNumber.Equals(SerialNumber)) { _device = device; break; } } if (_device != null) { _device.TryOpen(out _stream); } return(_stream != null); }
public override bool Open(string devicePath) { var loader = new HidDeviceLoader(); // search for HID _currentHidDevice = loader.GetDevices(VendorId, ProductId).FirstOrDefault(); if (_currentHidDevice == null) { Log.ErrorFormat("Couldn't find device with VID: {0}, PID: {1}", VendorId, ProductId); return(false); } // open HID if (!_currentHidDevice.TryOpen(out _currentHidStream)) { Log.ErrorFormat("Couldn't open device {0}", _currentHidDevice); return(false); } // since these devices have no MAC address, generate one m_Mac = MacAddressGenerator.NewMacAddress; IsActive = true; Path = devicePath; return(IsActive); }
public static HidDevice Find(int vid, int pid, string vendor, string device, int featureSize) { HidDeviceLoader ldr = new HidDeviceLoader(); foreach (HidDevice dev in ldr.GetDevices()) { if (vid != 0 && dev.VendorID != vid) { continue; } if (pid != 0 && dev.ProductID != pid) { continue; } if (vendor != null && dev.Manufacturer != vendor) { continue; } if (device != null && dev.ProductName != device) { continue; } if (featureSize != 0 && dev.MaxFeatureReportLength != featureSize) { continue; } return(dev); } return(null); }
public override bool Open(string devicePath) { short vid, pid; GetHardwareId(devicePath, out vid, out pid); var loader = new HidDeviceLoader(); // search for HID _currentHidDevice = loader.GetDevices(vid, pid).FirstOrDefault(); if (_currentHidDevice == null) { Log.ErrorFormat("Couldn't find device with VID: {0}, PID: {1}", vid, pid); return(false); } // open HID if (!_currentHidDevice.TryOpen(out _currentHidStream)) { Log.ErrorFormat("Couldn't open device {0}", _currentHidDevice); return(false); } // since these devices have no MAC address, generate one DeviceAddress = PhysicalAddress.Parse(MacAddressGenerator.NewMacAddress); IsActive = true; Path = devicePath; return(IsActive); }
public string Attached() { if (LOADED) { throw new Exception("Cannot list devices when Started"); } _loader = new HidDeviceLoader(); deviceList = _loader.GetDevices(-1, -1, -1, ""); // List Multiple Devices connected string ListOfSerialNumbers = ""; for (int i = 0; i < deviceList.Count(); i++) { Dev = deviceList.ElementAt(i); if (i > 0) { ListOfSerialNumbers += "/"; } ListOfSerialNumbers += Dev.ProductName; } return(ListOfSerialNumbers); }
public Form1() { InitializeComponent(); //USB\VID_16C0 & PID_05DA\6 & F5178C3 & 0 & 3 HidDeviceLoader hidDeviceLoader = new HidDeviceLoader(); int? nullable = null; HidDevice hidDevice = hidDeviceLoader.GetDevices(5824, 1498, nullable, null).FirstOrDefault(d => d.MaxInputReportLength == 63); if (hidDevice != null) { object[] maxInputReportLength = new object[] { hidDevice.MaxInputReportLength, hidDevice.MaxOutputReportLength, hidDevice.MaxFeatureReportLength, hidDevice.DevicePath }; HidStream hidStream; if (hidDevice.TryOpen(out hidStream)) { byte[] numArray = new byte[hidDevice.MaxInputReportLength]; try { var num = hidStream.Read(numArray, 0, (int)numArray.Length); } catch (TimeoutException timeoutException) { Console.WriteLine("Read timed out."); } } } }
/// <summary> /// Initializes communication with the DTS Card /// </summary> /// <returns>True if update is sucessful, false if there was a problem.</returns> public bool initialize() { if (_device == null) { dispose(); } HidDeviceLoader deviceLoader = new HidDeviceLoader(); foreach (HidDevice device in deviceLoader.GetDevices(0x04d8, 0xf64e)) { if (device.SerialNumber.Equals(SerialNumber)) { _device = device; break; } #pragma warning restore CS0612 // Type or member is obsolete } if (_device != null) { _device.TryOpen(out _stream); } return(_stream != null); }
public HidManager() { HidDeviceLoader = new HidDeviceLoader(); FoundDevices = new ObservableCollection <HidDeviceRepresentation>(); _hidScanThread = new Thread(() => { while (true) { var currentDevices = HidDeviceLoader.GetDevices().Select(hidDevice => new HidDeviceRepresentation(hidDevice)).ToList(); if (!Thread.CurrentThread.IsAlive) { break; } Application.Current.Dispatcher.Invoke(() => { foreach (var newDevice in currentDevices.Where(device => !FoundDevices.Contains(device))) { FoundDevices.Add(newDevice); } }); Thread.Sleep(TimeSpan.FromSeconds(10)); } // ReSharper disable once FunctionNeverReturns }); _hidScanThread.Start(); }
public string GetProductNames() { int EVTXCHCount = 0; if (LOADED) { throw new Exception("Cannot list devices when Started"); } _loader = new HidDeviceLoader(); deviceList = _loader.GetDevices(-1, -1, -1, ""); // List Multiple Devices connected string ListOfProductNumbers = ""; for (int i = 0; i < deviceList.Count(); i++) { Dev = deviceList.ElementAt(i); if (Dev.ProductName.Contains("EventExchanger")) { if (EVTXCHCount++ > 1) { ListOfProductNumbers += "/"; } ListOfProductNumbers += Dev.ProductName; } } return(ListOfProductNumbers); }
public static HidDevice GetConfigInterface() { var loader = new HidDeviceLoader(); // todo: use foreach/window instead of firstordefault return(loader.GetDevices(0x04d8, 0x0058).FirstOrDefault(device => device.ProductName == "NinHID CFG" || (device.MaxInputReportLength == device.MaxOutputReportLength && device.MaxInputReportLength == 9))); }
public static IEnumerable <MusiaConfigInterface> GetMusiaConfigInterfaces() { var ldr = new HidDeviceLoader(); foreach (HidDevice dev in ldr.GetDevices(0x1209, 0x8844).Where(d => d.ProductName.Contains("config"))) { yield return(new MusiaConfigInterface(dev)); } }
public PSDDevice[] FindConnectedPsds() { var psds = _loader.GetDevices().Where( d => d.MaxInputReportLength == _configSection.InputReportLength && d.VendorID == _configSection.VID && d.ProductID == _configSection.PID); return(psds.Select(a => new PSDDevice(a)).ToArray()); }
public void LoadDevice() { var loader = new HidDeviceLoader(); Thread.Sleep(2000); // Give a bit of time so our timing below is more valid as a benchmark. Device = loader.GetDevices(1356, 2).FirstOrDefault(); if (Device == null) { throw new ApplicationException("Failed to open device."); } }
public WindowsHIDSensorGroup(ISettings settings) { // No implementation for WindowsHIDSensor on Unix systems int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { return; } HidDeviceLoader loader = new HidDeviceLoader(); var deviceList = loader.GetDevices().ToArray(); HidDevice selected = loader.GetDevices(1155, 22288).FirstOrDefault();//VID 1155, PID 22288, if (selected != null) { hardware.Add(new WindowsHIDSensor(selected, settings)); } }
/// <summary> /// Find all BlinkStick devices. /// </summary> /// <returns>An array of BlinkStick devices</returns> public static BlinkStick[] FindAll() { List <BlinkStick> result = new List <BlinkStick>(); HidDeviceLoader loader = new HidDeviceLoader(); foreach (HidDevice adevice in loader.GetDevices(VendorId, ProductId).ToArray()) { BlinkStick hid = new BlinkStick(); hid.device = adevice; result.Add(hid); } return(result.ToArray()); }
public HidManager() { try { var loader = new HidDeviceLoader(); var device = loader.GetDevices(0x1770, 0xff00).First(); device.TryOpen(out _stream); } catch { MessageBox.Show("Error while loading the USB device, the program will now quit.", "Error !", MessageBoxButton.OK, MessageBoxImage.Warning); Environment.Exit(1); } }
/// <summary> /// Create object using VendorID and ProductID. Will throw exception if no USBLED is found. /// </summary> /// <param name="vendorID">Example to 0x1D34</param> /// <param name="productID">Example to 0x0008</param> /// <param name="deviceIndex">Zero based device index if you have multiple devices plugged in.</param> public DreamCheekyBTN(int vendorID, int productID, int deviceIndex = 0) { var loader = new HidDeviceLoader(); var devices = new List <HidDevice>(loader.GetDevices(vendorID, productID)); if (deviceIndex >= devices.Count) { throw new ArgumentOutOfRangeException("deviceIndex", String.Format("VID={0},PID={1},DeviceIndex={2} is invalid. There are only {3} devices connected.", vendorID, productID, deviceIndex, devices.Count)); } HidBTN = devices[deviceIndex]; if (!init()) { throw new Exception(String.Format("Cannot find USB HID Device with VendorID=0x{0:X4} and ProductID=0x{1:X4}", vendorID, productID)); } ActivatedMessage = Messages.BUTTON_PRESSED; }
private static void HID_CheckConnectionThread() { byte[] RxBuff = new byte[65]; byte[] TxBuff = new byte[65]; Disconnected: while (LevelingSystemDevice == null) { Thread.Sleep(100); LevelingSystemDevice = loader.GetDevices(2003, 7003).FirstOrDefault(d => d.MaxInputReportLength == 65); } DataHanlderClass.ChangeRadioButtonState(MW.ConnectedInd, true, "Connected"); UpdateZeroData = true; if (!LevelingSystemDevice.TryOpen(out USB_Stream)) { MessageBox.Show("Failed to connect to device", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(2); } using (USB_Stream) { while (true) { try { RxBuff = USB_Stream.Read(); if (TXQueue.Count > 0) { TxBuff = TXQueue.Dequeue(); USB_Stream.Write(TxBuff); } } catch { USB_Stream.Close(); LevelingSystemDevice = null; DataHanlderClass.ChangeRadioButtonState(MW.ConnectedInd, false, "Disconnected"); goto Disconnected; } if (RxBuff != null) { RxQueue.Enqueue(RxBuff); } Thread.Sleep(1); } } }
public void init_hid_device() { //var device_list = (from x in hid.enumerate(this.VENDOR_ID, this.PRODUCT_ID) // where x["interface_number"] == this.IFACE_NUM // select x).ToList(); //if (device_list.Count == 0) //{ // throw Exception("No devices found. See: https://github.com/gfduszynski/cm-rgb/issues/9"); //} //this.device = hid.device(); //try //{ // this.device.open_path(device_list[0]["path"]); //} //catch (OSError) //{ // Console.WriteLine("Failed to access usb device. See: https://github.com/gfduszynski/cm-rgb/wiki/1.-Installation-&-Configuration#3-configuration"); // Console.WriteLine("Also check if other process is not using the device.\n"); // throw; //} var terp = new OpenConfiguration(); terp.SetOption(OpenOption.Exclusive, true); var loader = new HidDeviceLoader(); var devices = loader.GetDevices(VENDOR_ID, PRODUCT_ID).ToArray(); foreach (var tdevice in devices) { try { stream = tdevice.Open(terp); this.init_controller(); Debug.WriteLine("Well, that seemed to work"); break; } catch (Exception e) { Debug.WriteLine(e.Message); } } }
/// <summary> /// Create object using Device path. Example: DreamCheekyBTN(@"\\?\hid#vid_1d34&pid_0008#6&1067c3dc&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"). /// </summary> /// <param name="devicePath">Example: @"\\?\hid#vid_1d34&pid_0008#6&1067c3dc&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"</param> public DreamCheekyBTN(string devicePath) { var loader = new HidDeviceLoader(); var devices = loader.GetDevices(); foreach (var device in devices) { if (device.DevicePath == devicePath) { HidBTN = device; } } if (!init()) { throw new Exception(String.Format("Cannot find USB HID Device with DevicePath={0}", devicePath)); } ActivatedMessage = Messages.BUTTON_PRESSED; }
public bool Connect() { var loader = new HidDeviceLoader(); if (loader.GetDevices(VID, PID).Count() != 1) { return(false); } try { HidDevice tempDevice = new HidDeviceLoader().GetDevices(VID, PID).First(); device = tempDevice; return(isConnected); } catch { return(false); } }
/// <summary> /// Create object using VendorID and ProductID. Will throw exception if no USBLED is found. /// </summary> /// <param name="vendorID">Example to 0x1D34</param> /// <param name="productID">Example to 0x0004</param> /// <param name="deviceIndex">Zero based device index if you have multiple devices plugged in.</param> public DreamCheekyLED(int vendorID, int productID, int deviceIndex = 0) { Trace.WriteLine("Instantiating HidDeviceLoader..."); Loader = new HidDeviceLoader(); Trace.WriteLine(String.Format("Enumerating HID USB Devices (VendorID {0}, ProductID {1})...", vendorID, productID)); var devices = new List <HidDevice>(Loader.GetDevices(vendorID, productID)); if (deviceIndex >= devices.Count) { throw new ArgumentOutOfRangeException("deviceIndex", String.Format("deviceIndex={0} is invalid. There are only {1} devices connected.", deviceIndex, devices.Count)); } HidLED = devices[deviceIndex]; if (!init()) { throw new Exception(String.Format("Cannot find USB HID Device with VendorID=0x{0:X4} and ProductID=0x{1:X4}", vendorID, productID)); } }
private void Reconnect() // Попытка подключиться к устройству { _stream = null; try { _guepard = _loader.GetDevices(_vid, _pid).FirstOrDefault(); _guepard?.TryOpen(out _stream); if (_stream != null) { _stream.ReadTimeout = 150; // Реальное время операции приблизительно 8 мс _stream.WriteTimeout = 150; } } catch (Exception) { //MessageBox.Show("Block 1\n" + e.Message); } }
public static IEnumerable <MuniaController> ListDevices() { var loader = new HidDeviceLoader(); foreach (var device in loader.GetDevices(0x04d8, 0x0058)) { if (device.ProductName == "NinHID NGC" || (device.MaxInputReportLength == 9 && device.MaxOutputReportLength == 0)) { yield return(new MuniaNgc(device)); } else if (device.ProductName == "NinHID N64" || device.MaxInputReportLength == 5) { yield return(new MuniaN64(device)); } else if (device.ProductName == "NinHID SNES" || device.MaxInputReportLength == 3) { yield return(new MuniaSnes(device)); } } }
public void BeginDiscovery() { if (m_usbNotifier != null) { throw new InvalidOperationException(); } // Test all the loaded HID devices to see if they're valid HidDeviceLoader loader = new HidDeviceLoader(); foreach (var device in loader.GetDevices()) { DeviceID id = new DeviceID(device); IInitDevice(id, DeviceEventType.DeviceDiscovered); } // Register for new device insertions m_usbNotifier = DeviceNotifier.OpenDeviceNotifier(); m_usbNotifier.OnDeviceNotify += IOnUsbNotify; }
static void Main(string[] args) { HidDeviceLoader loader = new HidDeviceLoader(); Thread.Sleep(2000); // Give a bit of time so our timing below is more valid as a benchmark. var stopwatch = new Stopwatch(); stopwatch.Start(); var deviceList = loader.GetDevices().ToArray(); stopwatch.Stop(); long deviceListTotalTime = stopwatch.ElapsedMilliseconds; Console.WriteLine("Complete device list (took {0} ms to get {1} devices):", deviceListTotalTime, deviceList.Length); foreach (HidDevice dev in deviceList) { Console.WriteLine(dev); } Console.WriteLine(); Console.WriteLine("Opening HID class device..."); #if SAMPLE_OPEN_AND_READ var device = loader.GetDevices(0x1b1c, 0x0c04).First(); if (device == null) { Console.WriteLine("Failed to open device."); Environment.Exit(1); } Console.Write(@" Max Lengths: Input: {0} Output: {1} Feature: {2} The operating system name for this device is: {3} " , device.MaxInputReportLength , device.MaxOutputReportLength , device.MaxFeatureReportLength , device.DevicePath ); HidStream stream; if (!device.TryOpen(out stream)) { Console.WriteLine("Failed to open device."); Environment.Exit(2); } using (stream) { int n = 0; while (true) { var bytes = new byte[device.MaxInputReportLength]; int count; try { count = stream.Read(bytes, 0, bytes.Length); } catch (TimeoutException) { Console.WriteLine("Read timed out."); continue; } if (count > 0) { Console.Write("* {0} : ", count); for (int i = 0; i < count && i < 62; i++) { Console.Write("{0:X} ", bytes[i]); } Console.WriteLine(); if (++n == 100) { break; } } } } #elif SAMPLE_DYMO_SCALE HidDevice scale = loader.GetDeviceOrDefault(24726, 344); if (scale == null) { Console.WriteLine("Failed to find scale device."); Environment.Exit(1); } HidStream stream; if (!scale.TryOpen(out stream)) { Console.WriteLine("Failed to open scale device."); Environment.Exit(2); } using (stream) { int n = 0; DymoScale scaleReader = new DeviceHelpers.DymoScale(stream); while (true) { int value, exponent; DymoScaleUnit unit; string unitName; DymoScaleStatus status; string statusName; bool buffered; scaleReader.ReadSample(out value, out exponent, out unit, out status, out buffered); unitName = DymoScale.GetNameFromUnit(unit); statusName = DymoScale.GetNameFromStatus(status); Console.WriteLine("{4} {0}: {1}x10^{2} {3} ", statusName, value, exponent, unitName, buffered ? "b" : " "); if (!buffered) { if (++n == 100) { break; } } } } #else #error "No sample selected." #endif Console.WriteLine("Press a key to exit..."); Console.ReadKey(); }