コード例 #1
0
        private async void OnTimerTriggered(object state)
        {
            if (_updateTimer == null)
            {
                return;
            }
            if (_semaphoreSlim.CurrentCount == 0)
            {
                return;
            }
            await _semaphoreSlim.WaitAsync();

            if (_runtimeDevice.TcpDeviceConnection == null || !_runtimeDevice.TcpDeviceConnection.LastTransactionSucceed)
            {
                return;
            }
            if (IsDisposed)
            {
                return;
            }
            if (_runtimeDevice.IsDeviceInitialized)
            {
                await _dataLoadingService?.UpdateAnalogs(_runtimeDevice);

                InterrogationCycleComplete?.Invoke();
            }
            if (_semaphoreSlim.CurrentCount == 0)
            {
                _semaphoreSlim.Release();
            }
        }
コード例 #2
0
        private async void OnTimerTriggered(object state)
        {
            if (_updateTimer == null)
            {
                return;
            }
            if (_semaphoreSlim.CurrentCount == 0)
            {
                return;
            }
            await _semaphoreSlim.WaitAsync();

            if (!_runtimeDevice.TcpDeviceConnection.LastTransactionSucceed)
            {
                if (!await _runtimeDevice.TcpDeviceConnection.OpenConnectionSession(false))
                {
                    _semaphoreSlim.Release();
                    return;
                }
                else
                {
                    if (IsDisposed)
                    {
                        return;
                    }
                    await _runtimeDevice.InitializeAsync();
                }
            }
            if (IsDisposed)
            {
                return;
            }
            if (_runtimeDevice.IsDeviceInitialized)
            {
                //  Debug.Print("---------------------------------------------------------------ОБМЕН   "+_stopwatch.Elapsed.ToString()+"----------------------------------------");
                //  _stopwatch.Reset();
                //  _stopwatch.Start();
                if (_isFullUpdate)
                {
                    await _dataLoadingService?.UpdateDataFromDeviceFull(_runtimeDevice);
                }
                else
                {
                    await _dataLoadingService?.UpdateDataFromDevicePartly(_runtimeDevice);
                }

                InterrogationCycleComplete?.Invoke();
            }
            if (_semaphoreSlim.CurrentCount == 0)
            {
                _semaphoreSlim.Release();
            }
        }