From 623f0e3bcea80f562c1c00afaa8bb2207e97e31d Mon Sep 17 00:00:00 2001
From: lch <1627445470@qq.com>
Date: Thu, 30 May 2024 18:24:16 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B6=88=E9=98=B2=E7=A7=BB?=
=?UTF-8?q?=E4=BB=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Execute/Model/FireProtectionRelocation.cs | 29 ++++++++++++
Service/Plc/Client/PlcMgr.cs | 47 ++++++++++++++-----
2 files changed, 63 insertions(+), 13 deletions(-)
create mode 100644 Service/Execute/Model/FireProtectionRelocation.cs
diff --git a/Service/Execute/Model/FireProtectionRelocation.cs b/Service/Execute/Model/FireProtectionRelocation.cs
new file mode 100644
index 0000000..e483229
--- /dev/null
+++ b/Service/Execute/Model/FireProtectionRelocation.cs
@@ -0,0 +1,29 @@
+namespace Service.Execute.Model;
+///
+/// 消防移仓
+///
+public class FireProtectionRelocation
+{
+ ///
+ /// 任务类型
+ /// 0.无任务
+ /// 1.换电任务
+ /// 2.移舱任务
+ /// 3.移出任务
+ /// 4.移入任务
+ /// 5.消防任务
+ ///
+ public ushort TaskType { get; set; }
+ ///
+ /// 入仓位选择
+ ///
+ public ushort EntrySelection { get; set; }
+ ///
+ /// 出仓位选择
+ ///
+ public ushort ExitSelection { get; set; }
+ ///
+ /// 电池包类型
+ ///
+ public ushort BatteryPackType { get; set; }
+}
\ No newline at end of file
diff --git a/Service/Plc/Client/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs
index bb84015..19434d0 100644
--- a/Service/Plc/Client/PlcMgr.cs
+++ b/Service/Plc/Client/PlcMgr.cs
@@ -1,4 +1,5 @@
using Autofac;
+using log4net;
using HslCommunication;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Utils;
@@ -346,7 +347,7 @@ public class PlcMgr
}
return bResult;
}
-
+ private static readonly ILog Log = LogManager.GetLogger(typeof(FireProtectionRelocation));
///
/// 消防移仓
///
@@ -354,22 +355,42 @@ public class PlcMgr
///
public static bool FireProtectionRelocation(ushort entrySelection)
{
+ //TODO::
bool bResult = false;
if (PlcClient != null)
{
- HostToPlc writeHostToPlc = new HostToPlc();
- writeHostToPlc.TaskType.Value = 5;
- writeHostToPlc.EntrySelection.Value = entrySelection;
- writeHostToPlc.ExitSelection.Value = 5;
- writeHostToPlc.BatteryPackType.Value = 0;
- //TODO:: 连续写多个寄存器 是否影响速度
- bool bResultTaskType = PlcClient.WriteValue(writeHostToPlc.TaskType);
- bool bResultEntrySelection = PlcClient.WriteValue(writeHostToPlc.EntrySelection);
- bool bResultExitSelection = PlcClient.WriteValue(writeHostToPlc.ExitSelection);
- bool bResultBatteryPackType = PlcClient.WriteValue(writeHostToPlc.BatteryPackType);
- if (bResultTaskType && bResultEntrySelection && bResultExitSelection && bResultBatteryPackType)
+ FireProtectionRelocation distributeTask = new()
+ {
+ TaskType = 5,
+ EntrySelection = entrySelection,
+ ExitSelection = 5,
+ BatteryPackType = 0
+ };
+ byte[] encode = ModelConvert.Encode(distributeTask);
+ //TODO::現在手動處理encode
+ for (int i = 0; i < encode.Length; i++)
+ {
+ if (i % 2 == 0)
+ {
+ var temp = encode[i + 1];
+ encode[i + 1] = encode[i];
+ encode[i] = temp;
+ }
+ }
+ //需要将数据转换成byte数组
+ OperateResult operateResult = PlcClient.Write("x=16;111",encode);
+
+ //查询人物状态
+ if (operateResult.IsSuccess)
{
- bResult = true;
+ bool readPlcTaskStatus9000 = false;
+ while (!readPlcTaskStatus9000)
+ {
+ Thread.Sleep(1000);
+ readPlcTaskStatus9000 = PlcMgr.ReadPlcTaskStatus() == 9000;
+ }
+
+ Log.Info($"execute FireProtectionRelocation success from EntrySelection ={distributeTask.EntrySelection}");
}
}
return bResult;