From bd385059ec25d73c610d8af7a43b23c2da7a91e2 Mon Sep 17 00:00:00 2001 From: zby <24947@USER> Date: Thu, 29 Aug 2024 17:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=B7=E8=BE=BE=E5=8A=A0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Padar/Client/PadarClient.cs | 2 +- Service/Padar/Codec/Decoder.cs | 16 +++++++++++----- WebStarter/Program.cs | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Service/Padar/Client/PadarClient.cs b/Service/Padar/Client/PadarClient.cs index d0933a4..1ed3f16 100644 --- a/Service/Padar/Client/PadarClient.cs +++ b/Service/Padar/Client/PadarClient.cs @@ -14,7 +14,7 @@ public class PadarClient : TcpClient /// /// 0-雷达不工作;1-无车;2-无电池,3-角度偏移过大;4-车辆靠后;5-车辆靠前;6-车辆到位 /// - public byte CarState { get; set; } + public byte CarState =new byte(); public static readonly byte[] StartChar = { 0xFE, 0x68 }; diff --git a/Service/Padar/Codec/Decoder.cs b/Service/Padar/Codec/Decoder.cs index 0cb3742..2783097 100644 --- a/Service/Padar/Codec/Decoder.cs +++ b/Service/Padar/Codec/Decoder.cs @@ -16,7 +16,7 @@ public class Decoder : ByteToMessageDecoder protected override void Decode(IChannelHandlerContext context, IByteBuffer buffer, List output) { - IByteBuffer? delimiter = FindDelimiter(buffer); + IByteBuffer delimiter = FindDelimiter(buffer); if (delimiter != null) { //分隔符索引 @@ -53,12 +53,18 @@ public class Decoder : ByteToMessageDecoder try { buffer.ReadBytes(data); + if (PadarMgr._PadarClient!=null) + { + PadarMgr._PadarClient.CarState = data[3]; + Log.Info($"receive {BitUtls.BytesToHexStr(data)}:{PadarMgr._PadarClient.CarState}"); + } + - PadarMgr._PadarClient.CarState = data[3]; - - Log.Info($"receive {BitUtls.BytesToHexStr(data)}:{PadarMgr._PadarClient.CarState}"); } - catch (Exception e) { } + catch (Exception e) + { + + } } } diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index f56d1ed..9de2ee1 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -180,6 +180,9 @@ AppInfo.Container = app.Services.GetAutofacRoot(); // PlcMgr.Init(); //} + +//雷达 +PadarMgr.InitClient(); ////启动换电流程 if (AppSettingsHelper.GetBool("swap", "enable")) {