From 7da39b7de7c7086d1c5d21c7ea6ad8765223930f Mon Sep 17 00:00:00 2001 From: rszn <645583145@qq.com> Date: Mon, 3 Jun 2024 14:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E7=A0=81=E6=8A=A5=E9=94=99=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Charger/Codec/Decoder.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Service/Charger/Codec/Decoder.cs b/Service/Charger/Codec/Decoder.cs index 0aaa06d..6704736 100644 --- a/Service/Charger/Codec/Decoder.cs +++ b/Service/Charger/Codec/Decoder.cs @@ -58,10 +58,18 @@ public class Decoder : ByteToMessageDecoder return; } - ASDU asdu = Parse(buffer, totalFrameLength, out var data); - Log.Info($"receive {JsonConvert.SerializeObject(asdu)}:{data} from {ChannelUtils.GetAttr(context.Channel, ChargerConst.ChargerSn)}"); - output.Add(asdu); - buffer.Clear(); + byte[]? data = null; + try + { + ASDU asdu = Parse(buffer, totalFrameLength, out data); + Log.Info($"receive {JsonConvert.SerializeObject(asdu)}:{data} from {ChannelUtils.GetAttr(context.Channel, ChargerConst.ChargerSn)}"); + output.Add(asdu); + buffer.Clear(); + } + catch (Exception e) + { + Log.Error($"decode fail msg={BitUtls.BytesToHexStr(data)}"); + } } } @@ -244,4 +252,4 @@ public class Decoder : ByteToMessageDecoder return asdu; } -} \ No newline at end of file +}