Example #1
0
        protected PortBase()
        {
            State.Where(_ => _ == PortState.Connected).Subscribe(_ =>
            {
                _lastSuccess = DateTime.Now;
                _logger.Info($"Port {this}: {_:G}");
            });
            State.Where(_ => _ == PortState.Error).Subscribe(_ =>
            {
                _errCnt++;
            });
            _enableStream.Where(_ => _).Subscribe(_ => Task.Factory.StartNew(TryConnect), _disposedCancel.Token);

            Observable.Timer(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(30)).Subscribe(_ =>
            {
                if (State.Value == PortState.Connected)
                {
                    _logger.Info($"Port {this}: work {DateTime.Now - _lastSuccess:g}; rx:{_rxBytes / 1024:F0} KiB; tx:{_rxBytes / 1024:F0} KiB; conn err:{_errCnt};");
                }
                else
                {
                    _logger.Info($"Port error {this}: {Error.Value?.Message}");
                }
            }, _disposedCancel.Token);
        }
Example #2
0
 protected PortBase()
 {
     _enableStream.Where(_ => _).Subscribe(_ => TryConnect(), _disposedCancel.Token);
 }