Exemplo n.º 1
0
        ///<summary>
        /// Opens the USB device handle.
        ///</summary>
        ///<returns>
        ///True if the device is already opened or was opened successfully.
        ///False if the device does not exists or is no longer valid.
        ///</returns>
        public override bool Open()
        {
            if (IsOpen)
            {
                return(true);
            }

            mUsbHandle = LibUsbDriverIO.OpenDevice(mDeviceFilename);
            if (!IsOpen)
            {
                UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "LibUsbDevice.Open Failed", this);
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens the USB device for communucation.
        /// </summary>
        /// <param name="deviceFilename">The LibUsb device filename to open.</param>
        /// <param name="usbDevice">The newly created UsbDevice.</param>
        /// <returns>True on success.</returns>
        public static bool Open(string deviceFilename, out LibUsbDevice usbDevice)
        {
            usbDevice = null;
            SafeFileHandle sfh = LibUsbDriverIO.OpenDevice(deviceFilename);

            if (!sfh.IsClosed && !sfh.IsInvalid)
            {
                usbDevice = new LibUsbDevice(LibUsbApi, sfh, deviceFilename);
                return(true);
            }
            else
            {
//                UsbDevice.Error(ErrorCode.DeviceNotFound, "The device is no longer attached or failed to open.", typeof(LibUsbDevice));
            }
            return(false);
        }