修改消防移仓

master
lch 6 months ago
parent 151e11aef5
commit 623f0e3bce

@ -0,0 +1,29 @@
namespace Service.Execute.Model;
/// <summary>
/// 消防移仓
/// </summary>
public class FireProtectionRelocation
{
/// <summary>
/// 任务类型
/// <para>0.无任务</para>
/// <para>1.换电任务</para>
/// <para>2.移舱任务</para>
/// <para>3.移出任务</para>
/// <para>4.移入任务</para>
/// <para>5.消防任务</para>
/// </summary>
public ushort TaskType { get; set; }
/// <summary>
/// 入仓位选择
/// </summary>
public ushort EntrySelection { get; set; }
/// <summary>
/// 出仓位选择
/// </summary>
public ushort ExitSelection { get; set; }
/// <summary>
/// 电池包类型
/// </summary>
public ushort BatteryPackType { get; set; }
}

@ -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));
/// <summary>
/// 消防移仓
/// </summary>
@ -354,22 +355,42 @@ public class PlcMgr
/// <returns></returns>
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;

Loading…
Cancel
Save