예제 #1
0
        public void OpenDevice(DeviceMode readMode, DeviceMode writeMode, ShareMode shareMode)
        {
            if (IsOpen)
            {
                return;
            }

            _deviceReadMode  = readMode;
            _deviceWriteMode = writeMode;
            _deviceShareMode = shareMode;

            try
            {
                ReadHandle  = OpenDeviceIO(_devicePath, readMode, NativeMethods.GENERIC_READ, shareMode);
                WriteHandle = OpenDeviceIO(_devicePath, writeMode, NativeMethods.GENERIC_WRITE, shareMode);
            }
            catch (Exception exception)
            {
                IsOpen = false;
                throw new Exception("Error opening HID device.", exception);
            }

            IsOpen = (ReadHandle.ToInt32() != NativeMethods.INVALID_HANDLE_VALUE &&
                      WriteHandle.ToInt32() != NativeMethods.INVALID_HANDLE_VALUE);
        }
예제 #2
0
        public void OpenDevice()
        {
            if (IsOpen)
            {
                return;
            }



            try
            {
                ReadHandle       = OpenDeviceIO(this.DevicePath, DeviceMode.NonOverlapped, Native.GENERIC_READ);
                WriteHandle      = OpenDeviceIO(this.DevicePath, DeviceMode.NonOverlapped, Native.GENERIC_WRITE);
                ReadAsyncHandle  = OpenDeviceIO(this.DevicePath, DeviceMode.Overlapped, Native.GENERIC_READ);
                WriteAsyncHandle = OpenDeviceIO(this.DevicePath, DeviceMode.Overlapped, Native.GENERIC_WRITE);
            }
            catch (Exception exception)
            {
                IsOpen = false;
                throw new Exception("Error opening HID device.", exception);
            }

            IsOpen = ReadHandle.ToInt32() != Native.INVALID_HANDLE_VALUE & WriteHandle.ToInt32() != Native.INVALID_HANDLE_VALUE;
        }