Inheritance: HidDevice
Exemplo n.º 1
0
        protected override bool TryCreateHidDevice(object key, out Device device)
        {
            var path = (HidDevicePath)key;

            device = WinHidDevice.TryCreate(path.DevicePath, path.DeviceID);
            return(device != null);
        }
Exemplo n.º 2
0
        protected override bool TryCreateDevice(object key, out HidDevice device, out object completionState)
        {
            string path      = (string)key;
            var    hidDevice = new WinHidDevice(path);
            IntPtr handle    = NativeMethods.CreateFileFromDevice(path, NativeMethods.EFileAccess.None, NativeMethods.EFileShare.All);

            device          = null;
            completionState = null;
            if (handle == (IntPtr)(-1))
            {
                return(false);
            }

            bool ok = false;

            try {
                ok = hidDevice.GetInfo(handle);
            } catch {
            }
            if (!ok)
            {
                NativeMethods.CloseHandle(handle);
                return(false);
            }

            device          = hidDevice;
            completionState = handle;
            return(true);
        }
Exemplo n.º 3
0
        internal void Init(string path, WinHidDevice device)
        {
            IntPtr handle = NativeMethods.CreateFileFromDevice(path, NativeMethods.EFileAccess.Read | NativeMethods.EFileAccess.Write, NativeMethods.EFileShare.All);
            if (handle == (IntPtr)(-1)) { throw new IOException("Unable to open HID class device."); }

            _device = device;
			_handle = handle;
			HandleInitAndOpen();
        }
Exemplo n.º 4
0
        protected override bool TryCreateDevice(object key, out HidDevice device, out object completionState)
        {
            string path = (string)key; var hidDevice = new WinHidDevice(path);
            IntPtr handle = NativeMethods.CreateFileFromDevice(path, NativeMethods.EFileAccess.None, NativeMethods.EFileShare.All);
            device = null; completionState = null; if (handle == (IntPtr)(-1)) { return false; }

            bool ok = false;
            try { ok = hidDevice.GetInfo(handle); } catch { }
            if (!ok) { NativeMethods.CloseHandle(handle); return false; }

            device = hidDevice; completionState = handle;
            return true;
        }
Exemplo n.º 5
0
        internal void Init(string path, WinHidDevice device)
        {
            IntPtr handle = NativeMethods.CreateFileFromDevice(path, NativeMethods.EFileAccess.Read | NativeMethods.EFileAccess.Write, NativeMethods.EFileShare.All);

            if (handle == (IntPtr)(-1))
            {
                throw new IOException("Unable to open HID class device.");
            }

            _device = device;
            _handle = handle;
            HandleInitAndOpen();
        }
Exemplo n.º 6
0
        internal static WinHidDevice TryCreate(string path, string id)
        {
            var d = new WinHidDevice()
            {
                _path = path, _id = id
            };

            return(d.TryOpenToGetInfo(handle =>
            {
                NativeMethods.HIDD_ATTRIBUTES attributes = new NativeMethods.HIDD_ATTRIBUTES();
                attributes.Size = Marshal.SizeOf(attributes);
                if (!NativeMethods.HidD_GetAttributes(handle, ref attributes))
                {
                    return false;
                }

                // Get VID, PID, version.
                d._pid = attributes.ProductID;
                d._vid = attributes.VendorID;
                d._version = attributes.VersionNumber;
                return true;
            }) ? d : null);
        }
Exemplo n.º 7
0
 internal WinHidStream(WinHidDevice device)
     : base(device)
 {
     _closeEventHandle = NativeMethods.CreateManualResetEventOrThrow();
 }