Ejemplo n.º 1
0
        public virtual async Task <MBusFrame> ReadDevice(int deviceId, bool resetBeforeRead, int deviceTimeout)
        {
            try
            {
                Open();
                if (_config.ResetBeforeRead || resetBeforeRead)
                {
                    var init = await ResetDevice(deviceId);

                    if (init == null)
                    {
                        return(null);
                    }
                }
                MBusFrame readFrame = MBusFrame.CreateShortFrame(MBus.ControlMaskReqUd2, (byte)deviceId);
                await TelegramMonitor.NotifyTelegram(TelegramDirection.Output, "SELF", deviceId.ToString(), readFrame.ToString(), "");
                await WriteFrame(readFrame);

                var res = await ReadFrame();

                if (res != null)
                {
                    await TelegramMonitor.NotifyTelegram(TelegramDirection.Output, res.AddressField.ToString(), "SELF", res.ToString(), "");
                }

                return(res);
            }
            catch
            {
                Close();
                throw;
            }
        }
Ejemplo n.º 2
0
        public virtual async Task <MBusFrame> ResetDevice(int deviceId)
        {
            try
            {
                Open();
                MBusFrame readFrame = MBusFrame.CreateShortFrame(MBus.ControlMaskSndUd, (byte)deviceId);

                Console.WriteLine(ByteArrayToString(readFrame.ToByteFrame()));
                await WriteFrame(readFrame);

                return(await ReadFrame());
            }
            catch
            {
                Close();
                throw;
            }
        }