Example #1
0
        public void BeforeEach()
        {
            _enumerator = new HidEnumerator();
            var firstDevice = _enumerator.Enumerate().FirstOrDefault();

            _devicePath = firstDevice != null ? firstDevice.DevicePath : "";
        }
Example #2
0
        public static void Main(String[] args)
        {
            var        hidDevices = new HidEnumerator().Enumerate(VendorId, ProductId);
            IHidDevice device     = null;

            try
            {
                device = hidDevices.Single(hd => hd.Capabilities.UsagePage == -256);
                device.Write(ReadTemperateureCommand);
                var data = device.Read();
                while (data.Status != HidDeviceData.ReadStatus.Success)
                {
                    ;
                }
                device.CloseDevice();

                CultureInfo ci = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name);
                ci.NumberFormat.NumberDecimalSeparator = ".";
                System.Threading.Thread.CurrentThread.CurrentCulture = ci;

                Console.Write("{\"in\":" + Convert(data.Data[3], data.Data[4]) + ",\"out\":" + Convert(data.Data[5], data.Data[6]) + "}");
            }
            catch (Exception e)
            {
                Console.Write("Device is not connected");
                Console.ReadLine();
                Environment.Exit(-1);
            }
        }
Example #3
0
        public override void StartScanning()
        {
            _scanning = true;
            var hidDevices = new HidEnumerator();

            foreach (var hid in hidDevices.Enumerate())
            {
                try
                {
                    hid.ReadProduct(out var product);
                    hid.ReadManufacturer(out var vendor);
                    var prod = Encoding.Unicode.GetString(product);
                    var vend = Encoding.Unicode.GetString(vendor);
                    prod = prod.Substring(0, prod.IndexOf('\0'));
                    vend = vend.Substring(0, vend.IndexOf('\0'));

                    BpLogger.Trace("Found HID device (" +
                                   hid.Attributes.VendorHexId + ":" + hid.Attributes.ProductHexId +
                                   "): " + vend + " - " + prod);

                    var factories = _deviceFactories.Where(x =>
                                                           x.MayBeDevice(hid.Attributes.VendorId, hid.Attributes.ProductId));
                    var buttplugHidDeviceFactories = factories as HidDeviceFactory[] ?? factories.ToArray();
                    if (buttplugHidDeviceFactories.Length != 1)
                    {
                        if (buttplugHidDeviceFactories.Any())
                        {
                            BpLogger.Warn($"Found multiple HID factories for {hid.Attributes.VendorHexId}:{hid.Attributes.ProductHexId}");
                            buttplugHidDeviceFactories.ToList().ForEach(x => BpLogger.Warn(x.GetType().Name));
                        }
                        else
                        {
                            // BpLogger.Trace("No BLE factories found for device.");
                        }

                        continue;
                    }

                    var factory = buttplugHidDeviceFactories.First();
                    BpLogger.Debug($"Found HID factory: {factory.GetType().Name}");

                    var d = factory.CreateDevice(hid);
                    InvokeDeviceAdded(new DeviceAddedEventArgs(d));
                }
                catch (Exception e)
                {
                    // TODO Figure out what exceptions can actually be thrown here.
                    BpLogger.Error(e.Message);
                }
            }

            _scanning = false;
            InvokeScanningFinished();
        }
Example #4
0
        /// <summary>
        ///     Search and collect information.
        /// </summary>
        /// <returns>A collection of information about devices found..</returns>
        public IEnumerable <RelayInfo> CollectInfo()
        {
            var usbHid = new HidEnumerator();
            var result = usbHid.CollectInfo()
                         .Where(x => x.VendorID == 0x16C0 && x.ProductId == 0x05DF)
                         .Select(this.GetInfo)
                         .Where(x => x != null)
                         .ToArray();

            return(result);
        }
Example #5
0
        private void BeforeEach()
        {
            enumerator = new HidEnumerator();
            var firstDevice = enumerator.Enumerate().FirstOrDefault();

            if (firstDevice != null)
            {
                devicePath = firstDevice.DevicePath;
            }
            else
            {
                devicePath = "";
            }
        }
Example #6
0
        /// <summary>
        /// Tries to create a <see cref="RgbHidBase"/> of the specified type.
        /// </summary>
        /// <param name="rgbDeviceType">Type of the RGB device.</param>
        /// <param name="rgbDevice">The RGB device.</param>
        /// <returns>True if the device was successfully created; otherwise, false.</returns>
        public static bool TryCreate(RgbDeviceType rgbDeviceType, out RgbHidBase rgbDevice)
        {
            rgbDevice = null;
            switch (rgbDeviceType)
            {
            case RgbDeviceType.CorsairK70Rgb:
                var hidDevice = new HidEnumerator().Enumerate(K70RgbMappings.CorsairVendorId, K70RgbMappings.K70RgbProductId).Where(device => device.Capabilities.OutputReportByteLength == K70RgbMappings.K70RgbPayloadSize).First();

                if (hidDevice == null)
                {
                    return(false);
                }

                rgbDevice = new K70Rgb(hidDevice);
                break;

            default:
                break;
            }

            return(rgbDevice != null);
        }
Example #7
0
        public BigRedButton()
        {
            var hidEnumerator = new HidEnumerator();

            device = hidEnumerator.Enumerate(VendorId, ProductId).FirstOrDefault();
        }