Esempio n. 1
0
        private async void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _timer.Stop();

            await _waitSemaphore.WaitAsync();

            try
            {
                DriverContext.Logger.LogTrace("Try read oms device...");
                var frame = await _mbus.TryReadFrame();

                if (frame != null)
                {
                    DriverContext.Logger.LogTrace($"Read frame...1({frame.GetType()})");

                    MBusFrame data = null;
                    if (frame is ShortFrame)
                    {
                        await _mbus.SendAck();


                        data = await _mbus.TryReadFrame();
                    }
                    else
                    {
                        data = frame;
                    }
                    if (data != null)
                    {
                        DriverContext.Logger.LogTrace($"Read frame...2({data.GetType()})");
                        DecryptFrame(data);
                        await _mbus.SendAck();
                    }
                    else
                    {
                        DriverContext.Logger.LogDebug($"could not read frame");
                    }
                }
            }
            finally
            {
                _waitSemaphore.Release(1);
            }

            _timer.Start();
        }
Esempio n. 2
0
        private async void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            await _waitSemaphore.WaitAsync();

            try
            {
                var data = await _mbus.SendAck();

                DecryptFrame(data);
            }
            finally
            {
                _waitSemaphore.Release(1);
            }
        }