SirenOfShame.Lib.Device.SirenOfShameDevice.TryConnect C# (CSharp) Method

TryConnect() public method

public TryConnect ( ) : bool
return bool
        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;
            }
        }

Usage Example

 public void GetLedPatterns()
 {
     ISirenOfShameDevice sos = new SirenOfShameDevice();
     sos.TryConnect();
     var patterns = sos.LedPatterns;
     foreach (var ledPattern in patterns)
     {
         Console.Out.WriteLine("ledPattern = {0} {1}", ledPattern.Id, ledPattern.Name);
     }
 }
All Usage Examples Of SirenOfShame.Lib.Device.SirenOfShameDevice::TryConnect