Example #1
0
        internal Win32HidDevice([NotNull] string path, [NotNull] SafeObjectHandle handle, bool ownHandle,
            [CanBeNull] Win32HidDeviceInformation knownInformation)
        {
            if (path == null) throw new ArgumentNullException(nameof(path));
            if (handle == null) throw new ArgumentNullException(nameof(handle));

            this.ownHandle = ownHandle;
            Handle = handle;
            
            Information = knownInformation ?? new Win32HidDeviceInformationLazy(path, handle);
        }
Example #2
0
        internal static Win32HidDevice FromPath([NotNull] string path, ACCESS_MASK accessMode,
                                                [CanBeNull] Win32HidDeviceInformation knownInformation)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var handle = OpenHandle(path, accessMode, true);

            return(new Win32HidDevice(path, handle, true, knownInformation));
        }
Example #3
0
        public Win32HidDeviceInformationStored([NotNull] Win32HidDeviceInformation other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            Path         = other.Path;
            Capabilities = other.Capabilities;
            SerialNumber = other.SerialNumber;
            ProductId    = other.ProductId;
            VendorId     = other.VendorId;
            Version      = other.Version;
            Manufacturer = other.Manufacturer;
            Product      = other.Product;
        }
Example #4
0
        internal Win32HidDevice([NotNull] string path, [NotNull] SafeObjectHandle handle, bool ownHandle,
                                [CanBeNull] Win32HidDeviceInformation knownInformation)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (handle == null)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            this.ownHandle = ownHandle;
            Handle         = handle;

            Information = knownInformation ?? new Win32HidDeviceInformationLazy(path, handle);
        }
Example #5
0
        private static Win32HidDevice FromId([NotNull] string deviceId, HidDeviceAccessMode accessMode,
                                             [CanBeNull] Win32HidDeviceInformation knownInformation)
        {
            if (deviceId == null)
            {
                throw new ArgumentNullException(nameof(deviceId));
            }
            switch (accessMode)
            {
            case HidDeviceAccessMode.Read:
                return(Win32HidDevice.FromPath(deviceId, ACCESS_MASK.GenericRight.GENERIC_READ, knownInformation));

            case HidDeviceAccessMode.Write:
                return(Win32HidDevice.FromPath(deviceId, ACCESS_MASK.GenericRight.GENERIC_WRITE, knownInformation));

            case HidDeviceAccessMode.ReadWrite:
                return(Win32HidDevice.FromPath(deviceId,
                                               ACCESS_MASK.GenericRight.GENERIC_READ | ACCESS_MASK.GenericRight.GENERIC_WRITE, knownInformation));

            default:
                throw new ArgumentException("Access mode not supported: " + accessMode, nameof(accessMode));
            }
        }
Example #6
0
 internal Task <Win32HidDevice> FromIdAsync(string deviceId, HidDeviceAccessMode accessMode,
                                            [CanBeNull] Win32HidDeviceInformation knownInformation, CancellationToken cancellationToken)
 {
     return(TaskEx.Run(() => FromId(deviceId, accessMode, knownInformation), cancellationToken));
 }