diff --git a/Entity/Constant/StationParamConst.cs b/Entity/Constant/StationParamConst.cs
index 500c9ac..bf02638 100644
--- a/Entity/Constant/StationParamConst.cs
+++ b/Entity/Constant/StationParamConst.cs
@@ -207,6 +207,8 @@ public class StationParamConst
public static readonly string StationStatus = "Station.StationStatus";
public static readonly string StationWay = "Station.StationWay";
public static readonly string StationModel = "Station.StationModel";
+ //换电启动模式
+ public static readonly string SwapInitiateMode = "Station.SwapInitiateMode";
#region Tbox
diff --git a/Service/Execute/Api/PlcApi.cs b/Service/Execute/Api/PlcApi.cs
index c43e527..758ffd2 100644
--- a/Service/Execute/Api/PlcApi.cs
+++ b/Service/Execute/Api/PlcApi.cs
@@ -182,5 +182,19 @@ public class PlcApi
Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}");
return readPlcTaskStatus;
}
+
+ ///
+ /// 读实体按钮状态
+ ///
+ ///
+ public static bool ReadPhysicalButtonState()
+ {
+ PlcMgr.ResetPlc();
+ Log.Info($"PlcApi start ReadPhysicalButtonState ");
+ var readPhysicalButtonState = PlcMgr.PhysicalButtonStateRadar();
+ Log.Info($"PlcApi ReadPhysicalButtonState resp= {readPhysicalButtonState}");
+ return readPhysicalButtonState;
+ }
+
}
diff --git a/Service/Execute/Step/CarCtrlState.cs b/Service/Execute/Step/CarCtrlState.cs
index 64410fb..896834a 100644
--- a/Service/Execute/Step/CarCtrlState.cs
+++ b/Service/Execute/Step/CarCtrlState.cs
@@ -9,6 +9,8 @@ using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
+using Service.Init;
+using Service.MyTask;
using Service.Station;
namespace Service.Execute.Step;
@@ -59,11 +61,16 @@ public class CarCtrlState : IState
return SwappingStateMachine.ReturnWithInvokeErr(tBoxEnergyDown, ExceptionReason.None);
}
- //请操作换电启动按钮
- SoundApi.PlayOneSound((int) InfoEnum.SwapInfo.InfoManualStartSwap);
- Thread.Sleep(2000);
+ //是否为拍按钮启动
+ InvokeStatus startButton = StartButton(machine);
+ if (startButton != InvokeStatus.Done)
+ {
+ return SwappingStateMachine.ReturnWithInvokeErr(startButton, ExceptionReason.None);
+ }
+
+
+ //Thread.Sleep(2000);
-
return new StateResult()
{
@@ -88,6 +95,7 @@ public class CarCtrlState : IState
//查询车辆锁止状态
Task carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
var resultHeartBeatMsg = carInfo.Result.CarStatus;
+
if (resultHeartBeatMsg?.LockStatus == 1 || machine.ManualConfirmCarUnlockFlag)
{
machine.ManualConfirmCarUnlockFlag = false;
@@ -95,6 +103,10 @@ public class CarCtrlState : IState
machine.VelUnlockFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelUnlockFlag,
machine);
+ {//开始下发电池包锁状态
+ PlcRealTimeTask.LockStatusTask = true;
+
+ }
}
}
}, () =>
@@ -218,6 +230,9 @@ public class CarCtrlState : IState
_log.Info("begin plc CheckChannelStatus");
Thread.Sleep(2000);
var channelStatus = PlcApi.ChannelStatus();
+ PlcRealTimeTask.cameraTask = true;//开始记录拍照偏移日志
+ PlcRealTimeTask.VehicleParkingStatusTask = true;//开始下发车辆驻车状态
+
if (count % 10 == 0)
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.CarTakePhotoInfo);
@@ -247,4 +262,39 @@ public class CarCtrlState : IState
return null;
}
+
+
+
+ ///
+ /// 收到实体按钮已拍
+ ///
+ ///
+ ///
+ public InvokeStatus StartButton(SwappingStateMachine machine)
+ {
+ return Invoker.Invoke("plc StartButton", 500, 5, machine.IsCanceled,
+ () => machine.PhysicalButtonState, () =>
+ {
+ if (StaticStationInfo.SwapInitiateMode == 2)
+ {
+ if (PlcApi.ReadPhysicalButtonState())
+ {
+ machine.PhysicalButtonState = true;
+ }
+
+ SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoManualStartSwap);
+ }
+ else
+ {
+ machine.PhysicalButtonState = true;
+ }
+
+
+ if (machine.PhysicalButtonState)
+ {
+ // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag,machine);
+ }
+ }, () => { }, false, () => { }, 10,
+ InvokeStatus.None);
+ }
}
\ No newline at end of file
diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs
index 08842d9..2c49209 100644
--- a/Service/Execute/Step/DoSwappingState.cs
+++ b/Service/Execute/Step/DoSwappingState.cs
@@ -11,6 +11,7 @@ using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
+using Service.MyTask;
using Service.Station;
namespace Service.Execute.Step;
@@ -320,6 +321,13 @@ public class DoSwappingState : IState
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
machine.SwapStatus = 1;
+
+ {
+ PlcRealTimeTask.cameraTask = false;//结束记录拍照偏移日志
+ PlcRealTimeTask.LockStatusTask = false;//结束下发电池包锁状态
+ PlcRealTimeTask.VehicleParkingStatusTask = false;//结束下发车辆驻车状态
+ PlcRealTimeTask.RollerShutterTask= false;
+ }
}
}, () => { });
}
diff --git a/Service/Execute/Step/StationReadyState.cs b/Service/Execute/Step/StationReadyState.cs
index a360a16..24842f6 100644
--- a/Service/Execute/Step/StationReadyState.cs
+++ b/Service/Execute/Step/StationReadyState.cs
@@ -13,6 +13,7 @@ using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
+using Service.MyTask;
using Service.Station;
using Swapping.Business.Common;
@@ -146,6 +147,8 @@ public class StationReadyState : IState
machine.ExceptionReason = ExceptionReason.None;
_log.Info("entrance radar true");
machine.RadarInFlag = true;
+ PlcRealTimeTask.RollerShutterTask = true;//雷达检测到车保持卷帘门开启
+
}
});
}
diff --git a/Service/Execute/SwappingStateMachine.cs b/Service/Execute/SwappingStateMachine.cs
index 389af61..3317592 100644
--- a/Service/Execute/SwappingStateMachine.cs
+++ b/Service/Execute/SwappingStateMachine.cs
@@ -118,6 +118,9 @@ public class SwappingStateMachine : IDisposable
public bool TboxEnergyUpFlag = false;
+ //实体按钮
+ public bool PhysicalButtonState = false;
+
//开始换电
public bool StartSwappingFlag = false;
diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs
index 152d66c..8e7d60f 100644
--- a/Service/Init/StaticStationInfo.cs
+++ b/Service/Init/StaticStationInfo.cs
@@ -71,6 +71,14 @@ public class StaticStationInfo
get => int.Parse(Resolve(StationParamConst.SwapSoc));
set => Set(StationParamConst.SwapSoc, value);
}
+ ///
+ /// 换电启动模式:1自动启动;2:拍按钮启动
+ ///
+ public static byte SwapInitiateMode
+ {
+ get => byte.Parse(Resolve(StationParamConst.SwapInitiateMode));
+ set => Set(StationParamConst.SwapInitiateMode, value);
+ }
#region Tbox
@@ -202,7 +210,9 @@ public class StaticStationInfo
get => byte.Parse(Resolve(StationParamConst.AutoChargeEnabled));
set => Set(StationParamConst.AutoChargeEnabled, value);
}
+
+
#endregion
diff --git a/Service/MyTask/PlcHeartTask.cs b/Service/MyTask/PlcHeartTask.cs
index 54b926f..8bd3c23 100644
--- a/Service/MyTask/PlcHeartTask.cs
+++ b/Service/MyTask/PlcHeartTask.cs
@@ -40,12 +40,12 @@ public class PlcHeartTask: ITask
writeHostToPlc.ProtocolVersion2.Value = 0;
writeHostToPlc.ProtocolVersion3.Value = 1;
writeHostToPlc.CommunicationDiagnosis.Value = (ushort)(heart ? 1 : 0);
- writeHostToPlc.Years.Value = (ushort)DateTime.Now.Year;
- writeHostToPlc.Month.Value = (ushort)DateTime.Now.Month;
- writeHostToPlc.Day.Value = (ushort)DateTime.Now.Day;
- writeHostToPlc.Hour.Value = (ushort)DateTime.Now.Hour;
- writeHostToPlc.Points.Value = (ushort)DateTime.Now.Minute;
- writeHostToPlc.Seconds.Value = (ushort)DateTime.Now.Second;
+ //writeHostToPlc.Years.Value = (ushort)DateTime.Now.Year;
+ //writeHostToPlc.Month.Value = (ushort)DateTime.Now.Month;
+ //writeHostToPlc.Day.Value = (ushort)DateTime.Now.Day;
+ //writeHostToPlc.Hour.Value = (ushort)DateTime.Now.Hour;
+ //writeHostToPlc.Points.Value = (ushort)DateTime.Now.Minute;
+ //writeHostToPlc.Seconds.Value = (ushort)DateTime.Now.Second;
var lstBinInfo = BinInfoRepository.Query();
writeHostToPlc.ChargingStatus02.Value = (short)(lstBinInfo[1].ChargeStatus == 1 ? 1010 : 1000);
@@ -55,18 +55,19 @@ public class PlcHeartTask: ITask
writeHostToPlc.ChargingStatus06.Value = (short)(lstBinInfo[5].ChargeStatus == 1 ? 1010 : 1000);
writeHostToPlc.ChargingStatus07.Value = (short)(lstBinInfo[6].ChargeStatus == 1 ? 1010 : 1000);
writeHostToPlc.ChargingStatus08.Value = (short)(lstBinInfo[7].ChargeStatus == 1 ? 1010 : 1000);
+ //TODO 后面8个仓写9~16还是11~18
bool write01 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ProtocolVersion1);
bool write02 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ProtocolVersion2);
bool write03 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ProtocolVersion3);
bool write0 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.CommunicationDiagnosis);
- bool write1 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Years);
- bool write2 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Month);
- bool write3 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Day);
- bool write4 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Hour);
- bool write5 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Points);
- bool write6 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Seconds);
+ //bool write1 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Years);
+ //bool write2 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Month);
+ //bool write3 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Day);
+ //bool write4 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Hour);
+ //bool write5 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Points);
+ //bool write6 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Seconds);
bool writeCharge2 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus02);
bool writeCharge3 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus03);
bool writeCharge4 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus04);
diff --git a/Service/MyTask/PlcRealTimeTask.cs b/Service/MyTask/PlcRealTimeTask.cs
new file mode 100644
index 0000000..482bedb
--- /dev/null
+++ b/Service/MyTask/PlcRealTimeTask.cs
@@ -0,0 +1,128 @@
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Autofac.Attribute;
+using HybirdFrameworkCore.AutoTask;
+using HybirdFrameworkCore.Entity;
+using log4net;
+using Repository.Station;
+using Service.Execute;
+using Service.Execute.Api;
+using Service.Execute.Model.Tbox;
+using Service.Plc.Client;
+using Service.Plc.Msg;
+using Service.Station;
+using System.Reflection.PortableExecutable;
+
+namespace Service.MyTask;
+
+///
+/// 电池充电是风扇启停
+///
+[Scope]
+public class PlcRealTimeTask : ITask
+{
+ private static readonly ILog Log = LogManager.GetLogger(typeof(PlcRealTimeTask));
+
+
+ public BinInfoRepository _binInfoRepository { get; set; }
+
+ private volatile bool _stop;
+
+ public static bool cameraTask=false;//相机偏移记录任务(查看通道状态开始,行车回归安全位置结束)
+ public static bool VehicleParkingStatusTask= false;//车辆驻车状态下发任务
+ public static bool LockStatusTask = false;//电池包锁状态下发任务
+
+ public static bool RollerShutterTask = false;//卷帘门是否保持开启状态
+
+ public string Name()
+ {
+ return "PlcRealTimeTask";
+ }
+
+ public int Interval()
+ {
+ return 1000 * 3;
+ }
+
+
+ public void Handle()
+ {
+ try
+ {
+ if (cameraTask)
+ {
+ if (PlcMgr.PlcToHostData != null)
+ {
+ Log.Info($"PlcRealTimeTask.CameraOffsetValue DeviationX={PlcMgr.PlcToHostData.DeviationX.Value}, DeviationY={PlcMgr.PlcToHostData.DeviationY.Value}" +
+ $",DeviationZ={PlcMgr.PlcToHostData.DeviationZ.Value},DeviationR={PlcMgr.PlcToHostData.DeviationR.Value},DeviationX2={PlcMgr.PlcToHostData.DeviationX2.Value}," +
+ $" DeviationY2={PlcMgr.PlcToHostData.DeviationY2.Value},DeviationZ2={PlcMgr.PlcToHostData.DeviationZ2.Value},DeviationR2={PlcMgr.PlcToHostData.DeviationR2.Value}");
+ }
+
+ }
+
+ var resultHeartBeatMsg = StationSoftMgr.SwappingStateMachine.BoxCarInfoModel?.CarStatus;
+
+ if (VehicleParkingStatusTask)
+ {
+
+ ushort vehicleParkingStatus = 0;
+ if (resultHeartBeatMsg != null)
+ {
+ if (resultHeartBeatMsg?.PowerStatus == 2 && resultHeartBeatMsg.Break == 1)
+ {
+ vehicleParkingStatus = 2;
+ }
+ else
+ {
+ vehicleParkingStatus = 1;
+ }
+ }
+
+ PlcMgr.WriteVehicleParkingStatus(vehicleParkingStatus);
+
+ }
+ if (LockStatusTask)
+ {
+ ushort lockStatus = 0;
+
+ if (resultHeartBeatMsg != null)
+ {
+ lockStatus = (ushort)(resultHeartBeatMsg?.LockStatus == 1 ? 1000 : 0);
+ }
+
+ PlcMgr.WriteStopCommand(lockStatus);
+ }
+
+ if (RollerShutterTask)
+ {
+ if (!PlcMgr.RollerShutterRadar())
+ {
+ PlcMgr.WriteRollerShutter(1000);
+ }
+ }
+ //else//需要关闭吗
+ //{
+ // PlcMgr.WriteRollerShutter(1010);
+ //}
+
+ }
+ catch (Exception e)
+ {
+ Log.Error($" PlcRealTimeTask err e={e}");
+ }
+ }
+
+ public bool Stoped()
+ {
+ return _stop;
+ }
+
+ public void Stop()
+ {
+ _stop = true;
+ }
+
+ public void ResetStop()
+ {
+ _stop = false;
+ }
+}
\ No newline at end of file
diff --git a/Service/Plc/Client/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs
index dfa6fc0..5d05a86 100644
--- a/Service/Plc/Client/PlcMgr.cs
+++ b/Service/Plc/Client/PlcMgr.cs
@@ -313,6 +313,8 @@ public class PlcMgr
return bResult;
}
+
+
///
/// 获取当前灯光状态
///
@@ -343,4 +345,90 @@ public class PlcMgr
return bResult;
}
+
+ ///
+ /// 写电池包锁止状态
+ ///
+ ///
+ public static bool WriteStopCommand(ushort lockStatus)
+ {
+ bool bResult = false;
+ if (PlcClient != null)
+ {
+ HostToPlc writeHostToPlc = new HostToPlc();
+ writeHostToPlc.StopCommand.Value = lockStatus;
+ bResult = PlcClient.WriteValue(writeHostToPlc.StopCommand);
+ }
+
+ return bResult;
+ }
+ ///
+ /// 下发车辆驻车状态
+ ///
+ ///
+ ///
+ public static bool WriteVehicleParkingStatus(ushort vehicleParkingStatus)
+ {
+ bool bResult = false;
+ if (PlcClient != null)
+ {
+ HostToPlc writeHostToPlc = new HostToPlc();
+ writeHostToPlc.VehicleParkingStatus.Value = vehicleParkingStatus;
+ bResult = PlcClient.WriteValue(writeHostToPlc.VehicleParkingStatus);
+ }
+
+ return bResult;
+ }
+
+ ///
+ /// 控制卷帘门
+ /// 0:无操作
+ ///1000:请求开启
+ ///1010:请求关闭
+ ///
+ ///
+ ///
+ public static bool WriteRollerShutter(ushort pollerShutter)
+ {
+ bool bResult = false;
+ if (PlcClient != null)
+ {
+ HostToPlc writeHostToPlc = new HostToPlc();
+ writeHostToPlc.RollerShutter.Value = pollerShutter;
+ bResult = PlcClient.WriteValue(writeHostToPlc.RollerShutter);
+ }
+
+ return bResult;
+ }
+
+ ///
+ /// 卷帘门是否开启
+ ///
+ ///
+ public static bool RollerShutterRadar()
+ {
+ if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
+ {
+ return PlcToHostData.RollerShutter.Value == 1000 ? true : false;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ ///
+ /// 实体按钮是否拍下
+ ///
+ ///
+ public static bool PhysicalButtonStateRadar()
+ {
+ if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
+ {
+ return PlcToHostData.PhysicalButtonState.Value == 1000 ? true : false;
+ }
+ else
+ {
+ return false;
+ }
+ }
}
\ No newline at end of file
diff --git a/Service/Plc/Msg/PlcToHost.cs b/Service/Plc/Msg/PlcToHost.cs
index e52b4a5..4a9a444 100644
--- a/Service/Plc/Msg/PlcToHost.cs
+++ b/Service/Plc/Msg/PlcToHost.cs
@@ -158,11 +158,11 @@ namespace Service.Plc.Msg
public ModbusProperty PercentageTorqueR { get; set; } = new(40309);
///
/// 卷帘门状态
- /// 0:无操作
- /// 1000:请求开启
- /// 1010:请求关闭
+ /// 0:未开启
+ /// 1000:已开启
+ /// 1010:已关闭
///
- public ModbusProperty RollerShutter { get; set; } = new(40116);
+ public ModbusProperty RollerShutter { get; set; } = new(40310);
//public ModbusProperty value6 { get; set; } = new(40116,length:12);
///
/// 左侧载行车设备状态
@@ -293,19 +293,19 @@ namespace Service.Plc.Msg
///
/// 右侧堆垛机相机x偏差
///
- public ModbusProperty DeviationX { get; set; } = new(40411);
+ public ModbusProperty DeviationX { get; set; } = new(40411, scale: 0.01);
///
/// 右侧堆垛机相机y偏差
///
- public ModbusProperty DeviationY { get; set; } = new(40412);
+ public ModbusProperty DeviationY { get; set; } = new(40412, scale: 0.01);
///
/// 右侧堆垛机相机z偏差
///
- public ModbusProperty DeviationZ { get; set; } = new(40413);
+ public ModbusProperty DeviationZ { get; set; } = new(40413, scale: 0.01);
///
/// 右侧堆垛机相机R偏差
///
- public ModbusProperty DeviationR { get; set; } = new(40414);
+ public ModbusProperty DeviationR { get; set; } = new(40414, scale: 0.01);
public ModbusProperty value11 { get; set; } = new(40409,length:13);
@@ -320,18 +320,18 @@ namespace Service.Plc.Msg
///
/// 左侧堆垛机相机x偏差
///
- public ModbusProperty DeviationX2 { get; set; } = new(40429);
+ public ModbusProperty DeviationX2 { get; set; } = new(40429, scale: 0.01);
///
/// 左侧堆垛机相机y偏差
///
- public ModbusProperty DeviationY2 { get; set; } = new(40430);
+ public ModbusProperty DeviationY2 { get; set; } = new(40430, scale: 0.01);
///
/// 左侧堆垛机相机z偏差
///
- public ModbusProperty DeviationZ2 { get; set; } = new(40431);
+ public ModbusProperty DeviationZ2 { get; set; } = new(40431, scale: 0.01);
///
/// 左侧堆垛机相机R偏差
///
- public ModbusProperty DeviationR2 { get; set; } = new(40432);
+ public ModbusProperty DeviationR2 { get; set; } = new(40432, scale: 0.01);
}
}
diff --git a/WebStarter/appsettings.dev.json b/WebStarter/appsettings.dev.json
index 032ac25..eaf30ab 100644
--- a/WebStarter/appsettings.dev.json
+++ b/WebStarter/appsettings.dev.json
@@ -2,7 +2,7 @@
"ConnectionStrings": {
"ConfigId": "master",
"DbType": "MySql",
- "SqlConnection": "server=180.76.133.253;Port=16306;Database=nhet_dev;Uid=root;Pwd=Rszn123;Charset=utf8;"
+ "SqlConnection": "server=127.0.0.1;Port=3306;Database=nhet_dev;Uid=root;Pwd=123456;Charset=utf8;"
},
"Update": {
"AutoUpdate": "false",