///<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); } SafeFileHandle sfhDev; bool bSuccess = WinUsbAPI.OpenDevice(out sfhDev, mDevicePath); if (bSuccess) { SafeWinUsbInterfaceHandle handle = new SafeWinUsbInterfaceHandle(); if ((bSuccess = WinUsbAPI.WinUsb_Initialize(sfhDev, ref handle))) { mSafeDevHandle = sfhDev; mUsbHandle = handle; mPowerPolicies = new PowerPolicies(this); } else { UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "Open:Initialize", typeof(UsbDevice)); } } else { UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "Open", typeof(UsbDevice)); } return(bSuccess); }
internal WinUsbDevice(UsbApiBase usbApi, SafeFileHandle usbHandle, SafeHandle handle, string devicePath) : base(usbApi, handle) { mDevicePath = devicePath; mSafeDevHandle = usbHandle; mPowerPolicies = new PowerPolicies(this); }
///<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; SafeFileHandle sfhDev; bool bSuccess = WinUsbAPI.OpenDevice(out sfhDev, mDevicePath); if (bSuccess) { SafeWinUsbInterfaceHandle handle = new SafeWinUsbInterfaceHandle(); if ((bSuccess = WinUsbAPI.WinUsb_Initialize(sfhDev, ref handle))) { mSafeDevHandle = sfhDev; mUsbHandle = handle; mPowerPolicies = new PowerPolicies(this); } else UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "Open:Initialize", typeof (UsbDevice)); } else UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "Open", typeof(UsbDevice)); return bSuccess; }