换电中读写Plc实时数据任务

master
xjl 4 months ago
parent 131c4f536c
commit 53c2307b80

@ -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

@ -182,5 +182,19 @@ public class PlcApi
Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}");
return readPlcTaskStatus;
}
/// <summary>
/// 读实体按钮状态
/// </summary>
/// <returns></returns>
public static bool ReadPhysicalButtonState()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi start ReadPhysicalButtonState ");
var readPhysicalButtonState = PlcMgr.PhysicalButtonStateRadar();
Log.Info($"PlcApi ReadPhysicalButtonState resp= {readPhysicalButtonState}");
return readPhysicalButtonState;
}
}

@ -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,10 +61,15 @@ 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<TboxCarInfoModel> 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;
}
/// <summary>
/// 收到实体按钮已拍
/// </summary>
/// <param name="machine"></param>
/// <returns></returns>
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);
}
}

@ -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;
}
}
}, () => { });
}

@ -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;//雷达检测到车保持卷帘门开启
}
});
}

@ -118,6 +118,9 @@ public class SwappingStateMachine : IDisposable
public bool TboxEnergyUpFlag = false;
//实体按钮
public bool PhysicalButtonState = false;
//开始换电
public bool StartSwappingFlag = false;

@ -71,6 +71,14 @@ public class StaticStationInfo
get => int.Parse(Resolve(StationParamConst.SwapSoc));
set => Set(StationParamConst.SwapSoc, value);
}
/// <summary>
/// 换电启动模式1自动启动2拍按钮启动
/// </summary>
public static byte SwapInitiateMode
{
get => byte.Parse(Resolve(StationParamConst.SwapInitiateMode));
set => Set(StationParamConst.SwapInitiateMode, value);
}
#region Tbox
@ -203,6 +211,8 @@ public class StaticStationInfo
set => Set(StationParamConst.AutoChargeEnabled, value);
}
#endregion

@ -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);

@ -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;
/// <summary>
/// 电池充电是风扇启停
/// </summary>
[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;
}
}

@ -313,6 +313,8 @@ public class PlcMgr
return bResult;
}
/// <summary>
/// 获取当前灯光状态
/// </summary>
@ -343,4 +345,90 @@ public class PlcMgr
return bResult;
}
/// <summary>
/// 写电池包锁止状态
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// 下发车辆驻车状态
/// </summary>
/// <param name="vehicleParkingStatus"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 控制卷帘门
/// 0:无操作
///1000请求开启
///1010请求关闭
/// </summary>
/// <param name="pollerShutter"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 卷帘门是否开启
/// </summary>
/// <returns></returns>
public static bool RollerShutterRadar()
{
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{
return PlcToHostData.RollerShutter.Value == 1000 ? true : false;
}
else
{
return false;
}
}
/// <summary>
/// 实体按钮是否拍下
/// </summary>
/// <returns></returns>
public static bool PhysicalButtonStateRadar()
{
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{
return PlcToHostData.PhysicalButtonState.Value == 1000 ? true : false;
}
else
{
return false;
}
}
}

@ -158,11 +158,11 @@ namespace Service.Plc.Msg
public ModbusProperty<short> PercentageTorqueR { get; set; } = new(40309);
/// <summary>
/// 卷帘门状态
/// <para>0:无操作</para>
/// <para>1000请求开启</para>
/// <para>1010请求关闭</para>
/// <para>0:未开启</para>
/// <para>1000开启</para>
/// <para>1010关闭</para>
/// </summary>
public ModbusProperty<ushort> RollerShutter { get; set; } = new(40116);
public ModbusProperty<ushort> RollerShutter { get; set; } = new(40310);
//public ModbusProperty<ushort> value6 { get; set; } = new(40116,length:12);
/// <summary>
/// 左侧载行车设备状态
@ -293,19 +293,19 @@ namespace Service.Plc.Msg
/// <summary>
/// 右侧堆垛机相机x偏差
/// </summary>
public ModbusProperty<short> DeviationX { get; set; } = new(40411);
public ModbusProperty<short> DeviationX { get; set; } = new(40411, scale: 0.01);
/// <summary>
/// 右侧堆垛机相机y偏差
/// </summary>
public ModbusProperty<short> DeviationY { get; set; } = new(40412);
public ModbusProperty<short> DeviationY { get; set; } = new(40412, scale: 0.01);
/// <summary>
/// 右侧堆垛机相机z偏差
/// </summary>
public ModbusProperty<short> DeviationZ { get; set; } = new(40413);
public ModbusProperty<short> DeviationZ { get; set; } = new(40413, scale: 0.01);
/// <summary>
/// 右侧堆垛机相机R偏差
/// </summary>
public ModbusProperty<short> DeviationR { get; set; } = new(40414);
public ModbusProperty<short> DeviationR { get; set; } = new(40414, scale: 0.01);
public ModbusProperty<ushort> value11 { get; set; } = new(40409,length:13);
@ -320,18 +320,18 @@ namespace Service.Plc.Msg
/// <summary>
/// 左侧堆垛机相机x偏差
/// </summary>
public ModbusProperty<short> DeviationX2 { get; set; } = new(40429);
public ModbusProperty<short> DeviationX2 { get; set; } = new(40429, scale: 0.01);
/// <summary>
/// 左侧堆垛机相机y偏差
/// </summary>
public ModbusProperty<short> DeviationY2 { get; set; } = new(40430);
public ModbusProperty<short> DeviationY2 { get; set; } = new(40430, scale: 0.01);
/// <summary>
/// 左侧堆垛机相机z偏差
/// </summary>
public ModbusProperty<short> DeviationZ2 { get; set; } = new(40431);
public ModbusProperty<short> DeviationZ2 { get; set; } = new(40431, scale: 0.01);
/// <summary>
/// 左侧堆垛机相机R偏差
/// </summary>
public ModbusProperty<short> DeviationR2 { get; set; } = new(40432);
public ModbusProperty<short> DeviationR2 { get; set; } = new(40432, scale: 0.01);
}
}

@ -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",

Loading…
Cancel
Save