Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }