public virtual bool Open(string devicePath) { GetHardwareId(devicePath); Path = devicePath.ToUpper(); if (GetDeviceHandle(Path)) { if (Usb.Initialize(FileHandle, ref _winUsbHandle)) { if (InitializeDevice()) { if (!LibusbKWrapper.Instance.SetPowerPolicyAutoSuspend(_winUsbHandle)) { Log.Warn("Couldn't alter power policy"); } IsActive = true; } else { Usb.Free(_winUsbHandle); _winUsbHandle = (IntPtr)INVALID_HANDLE_VALUE; } } else { CloseHandle(FileHandle); } } return(IsActive); }
public virtual bool Open(string devicePath) { GetHardwareId(devicePath); Path = devicePath.ToUpper(); if (GetDeviceHandle(Path)) { if (WinUsbWrapper.Initialize(FileHandle, ref _winUsbHandle)) { if (InitializeDevice()) { IsActive = true; } else { WinUsbWrapper.Free(_winUsbHandle); _winUsbHandle = (IntPtr)INVALID_HANDLE_VALUE; } } else { CloseHandle(FileHandle); } } return(IsActive); }
public virtual bool Stop() { IsActive = false; if (!(_winUsbHandle == (IntPtr)INVALID_HANDLE_VALUE)) { WinUsbWrapper.AbortPipe(_winUsbHandle, IntIn); WinUsbWrapper.AbortPipe(_winUsbHandle, BulkIn); WinUsbWrapper.AbortPipe(_winUsbHandle, BulkOut); WinUsbWrapper.Free(_winUsbHandle); _winUsbHandle = (IntPtr)INVALID_HANDLE_VALUE; } if (FileHandle != IntPtr.Zero) { CloseHandle(FileHandle); FileHandle = IntPtr.Zero; } return(true); }