LgBackLight.HidDevice.Open C# (CSharp) Метод

Open() статический приватный Метод

static private Open ( string devicePath ) : HidDevice
devicePath string
Результат HidDevice
        internal static HidDevice Open(string devicePath)
        {
            IntPtr handle = Kernel32.CreateFile(
                devicePath,
                (uint)FileAccess.Read,
                FileShare.ReadWrite,
                IntPtr.Zero,
                FileMode.Open,
                FileAttributes.Device,
                IntPtr.Zero);
            if (handle != Kernel32.InvalidHandleValue) {
                Hid.DeviceAttributes attributes;
                if (Hid.HidD_GetAttributes(handle, out attributes)) {
                    return new HidDevice(
                        handle,
                        devicePath,
                        attributes.VendorId,
                        attributes.ProductId,
                        attributes.VersionNumber);
                }
                // If we could not get the hid attributes,
                // then what we opened was not a hid device,
                // we need to close the handle nonetheless.
                Kernel32.CloseHandle(handle);
            }
            throw new Exception();
        }

Same methods

HidDevice::Open ( int vendorId, IEnumerable productIds ) : List
HidDevice::Open ( int vendorId, int productId ) : List

Usage Example

Пример #1
0
        private static void DeviceAdded(object sender, DeviceEventArgs args)
        {
            HidDevice hidDevice = HidDevice.Open(args.DevicePath);

            // We can be sure a hid device was be returned,
            // since we only registered device notifications
            // for hid devices.
            if (vendorId == hidDevice.VendorId &&
                productIds.Contains(hidDevice.ProductId))
            {
                // The device added appears to be a backlight device.
                devices.Add(args.DevicePath.ToUpper(), hidDevice);
            }
            else
            {
                // Not a backlight device, dispose!
                hidDevice.Dispose();
            }
        }
All Usage Examples Of LgBackLight.HidDevice::Open