/* open hid device */ public bool Open(HIDInfo dev) { /* safe file handle */ SafeFileHandle shandle; /* opens hid device file */ handle = Native.CreateFile(dev.Path, Native.GENERIC_READ | Native.GENERIC_WRITE, Native.FILE_SHARE_READ | Native.FILE_SHARE_WRITE, IntPtr.Zero, Native.OPEN_EXISTING, Native.FILE_FLAG_OVERLAPPED, IntPtr.Zero); /* whops */ if (handle == Native.INVALID_HANDLE_VALUE) { return(false); } /* build up safe file handle */ shandle = new SafeFileHandle(handle, false); /* prepare stream - async */ _fileStream = new FileStream(shandle, FileAccess.ReadWrite, 32, true); /* report status */ return(true); }
/* open device */ private static IntPtr Open(string path) { /* opens hid device file */ return(Native.CreateFile(path, Native.GENERIC_READ | Native.GENERIC_WRITE, Native.FILE_SHARE_READ | Native.FILE_SHARE_WRITE, IntPtr.Zero, Native.OPEN_EXISTING, Native.FILE_FLAG_OVERLAPPED, IntPtr.Zero)); }