public bool TryConnect()
 {
     _disconnecting = false;
     if (_connecting)
     {
         return(true);
     }
     _connecting = true;
     try
     {
         DeviceInterface deviceInterface = FindDevice();
         if (deviceInterface == null)
         {
             return(false);
         }
         Thread.Sleep(500);
         _deviceInterfaceFile = deviceInterface.OpenFile(PacketSize);
         var caps = _deviceInterfaceFile.Capabilities;
         _log.Debug("InputReportByteLength: " + caps.InputReportByteLength);
         _log.Debug("OutputReportByteLength: " + caps.NumberOutputDataIndices);
         _log.Debug("OutputReportByteLength: " + caps.OutputReportByteLength);
         BeginAsyncRead();
         ReadDeviceInfo();
         ReadAudioPatterns();
         ReadLedPatterns();
         OnConnected();
         return(true);
     }
     finally
     {
         _connecting = false;
     }
 }
Beispiel #2
0
 public void Dispose()
 {
     if (_handle != null)
     {
         _handle.Dispose();
         _handle = null;
     }
 }
 public void Dispose()
 {
     if (_handle != null)
     {
         _handle.Dispose();
         _handle = null;
     }
 }
Beispiel #4
0
        private bool TryOpen(int blockSize)
        {
            Dispose();

            DeviceInterface deviceInterface;
            Guid            hidGuid = DeviceInformationSet.GetHidGuid();

            using (var deviceInformationSet = new DeviceInformationSet(hidGuid, DiGetClassFlags.Present | DiGetClassFlags.DeviceInterface))
            {
                deviceInterface = deviceInformationSet.GetDeviceInterfaces(hidGuid)
                                  .Where(d => d.IsValidUsbDevice)
                                  .FirstOrDefault(dis => (dis.Details.DevicePath.Contains("16c0") && dis.Details.DevicePath.Contains("0478")) ||
                                                  (dis.Details.DevicePath.Contains("03eb") && dis.Details.DevicePath.Contains("2067")));
                if (deviceInterface != null)
                {
                    _handle = deviceInterface.OpenFile(blockSize + 3);
                    return(true);
                }

                return(false);
            }
        }
 private void OnDisconnected()
 {
     try
     {
         _disconnecting = true;
         IsConnected    = false;
         if (_deviceInterfaceFile != null)
         {
             _deviceInterfaceFile.Dispose();
             _deviceInterfaceFile = null;
             Thread.Sleep(500);
         }
         if (Disconnected != null)
         {
             Disconnected(this, new EventArgs());
         }
     }
     finally
     {
         _disconnecting = false;
     }
 }
 private void OnDisconnected()
 {
     try
     {
         _disconnecting = true;
         IsConnected = false;
         if (_deviceInterfaceFile != null)
         {
             _deviceInterfaceFile.Dispose();
             _deviceInterfaceFile = null;
             Thread.Sleep(500);
         }
         if (Disconnected != null)
         {
             Disconnected(this, new EventArgs());
         }
     }
     finally
     {
         _disconnecting = false;
     }
 }
 public bool TryConnect()
 {
     _disconnecting = false;
     if (_connecting)
     {
         return true;
     }
     _connecting = true;
     try
     {
         DeviceInterface deviceInterface = FindDevice();
         if (deviceInterface == null)
         {
             return false;
         }
         Thread.Sleep(500);
         _deviceInterfaceFile = deviceInterface.OpenFile(PacketSize);
         var caps = _deviceInterfaceFile.Capabilities;
         _log.Debug("InputReportByteLength: " + caps.InputReportByteLength);
         _log.Debug("OutputReportByteLength: " + caps.NumberOutputDataIndices);
         _log.Debug("OutputReportByteLength: " + caps.OutputReportByteLength);
         BeginAsyncRead();
         ReadDeviceInfo();
         ReadAudioPatterns();
         ReadLedPatterns();
         OnConnected();
         return true;
     }
     finally
     {
         _connecting = false;
     }
 }
        private bool TryOpen(int blockSize)
        {
            Dispose();

            DeviceInterface deviceInterface;
            Guid hidGuid = DeviceInformationSet.GetHidGuid();
            using (var deviceInformationSet = new DeviceInformationSet(hidGuid, DiGetClassFlags.Present | DiGetClassFlags.DeviceInterface))
            {
                deviceInterface = deviceInformationSet.GetDeviceInterfaces(hidGuid)
                    .Where(d => d.IsValidUsbDevice)
                    .FirstOrDefault(dis => (dis.Details.DevicePath.Contains("16c0") && dis.Details.DevicePath.Contains("0478"))
                        || (dis.Details.DevicePath.Contains("03eb") && dis.Details.DevicePath.Contains("2067")));
                if (deviceInterface != null)
                {
                    _handle = deviceInterface.OpenFile(blockSize + 3);
                    return true;
                }

                return false;
            }
        }