protected override bool TryCreateHidDevice(object key, out Device device) { var path = (HidDevicePath)key; device = WinHidDevice.TryCreate(path.DevicePath, path.DeviceID); return(device != null); }
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); }
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(); }
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; }
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); }
internal WinHidStream(WinHidDevice device) : base(device) { _closeEventHandle = NativeMethods.CreateManualResetEventOrThrow(); }