master
lxw 6 months ago
parent c6c56bdc5f
commit 604667d2aa

@ -1,5 +1,8 @@
namespace Entity.Constant; namespace Entity.Constant;
/// <summary>
///
/// </summary>
public class CloudEnum public class CloudEnum
{ {

@ -5,6 +5,7 @@ using HybirdFrameworkServices.Plc;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Init.Entity; using Service.Init.Entity;
using Service.Plc;
namespace Service namespace Service
{ {
@ -55,8 +56,7 @@ namespace Service
if (connected) if (connected)
{ {
PlcApi.master = master; PlcMgr.ModbusTcpMaster = master;
PlcApi.con = true;
break; break;
} }
@ -71,28 +71,29 @@ namespace Service
{ {
if (PlcApi.con) if (PlcApi.con)
{ {
var bytes01 = master.BatchReadHolderRegister(1, 115); var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null) if (bytes01 != null)
{ {
PlcApi.DataValidityTime = DateTime.Now; PlcApi.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcApi.hostToPlc); ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData);
} }
var bytes02 = master.BatchReadHolderRegister(201, 222); var bytes02 = master.BatchReadHolderRegister(201, 222);
if (bytes02 != null) if (bytes02 != null)
{ {
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcApi.plcToHost); ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData);
} }
var bytes03 = master.BatchReadHolderRegister(701, 10); var bytes03 = master.BatchReadHolderRegister(701, 10);
if (bytes03 != null) if (bytes03 != null)
{ {
PlcApi.DataValidityTime = DateTime.Now; PlcApi.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcApi.plcFault); ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData);
} }
//OperateResult<byte[]> result2 = ModbusTcpNet.Read("x=3;201", 222); //OperateResult<byte[]> result2 = ModbusTcpNet.Read("x=3;201", 222);
} }
} }
} }
} }

@ -11,7 +11,7 @@ namespace Service.Execute.Api;
public class CloudApi public class CloudApi
{ {
private const int TimeSpan = 30; private const int TimeSpan = 60;
/// <summary> /// <summary>
/// 云平台车辆认证 /// 云平台车辆认证

@ -3,15 +3,14 @@ using HybirdFrameworkServices.Plc;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Service.Cloud.Msg.Cloud.Req; using Service.Cloud.Msg.Cloud.Req;
using Service.Init.Entity; using Service.Init.Entity;
using Service.Plc;
namespace Service.Execute.Api; namespace Service.Execute.Api;
public class PlcApi public class PlcApi
{ {
public static HostToPlc hostToPlc = new HostToPlc(); private const int TimeSpan = 60;
public static PlcToHost plcToHost = new PlcToHost();
public static PlcFault plcFault = new PlcFault();
public static ModbusTcpMaster master;
/// <summary> /// <summary>
/// PLC是否连接 /// PLC是否连接
@ -36,7 +35,7 @@ public class PlcApi
{ {
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds) if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{ {
return plcToHost.RemoteLocalControlState.Value == 1010 ? true : false; return PlcMgr.PlcToHostData.RemoteLocalControlState.Value == 1010 ? true : false;
} }
else else
{ {
@ -52,7 +51,7 @@ public class PlcApi
{ {
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds) if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{ {
return plcToHost.RadarStatesIn.Value == 1000 ? true : false; return PlcMgr.PlcToHostData.RadarStatesIn.Value == 1000 ? true : false;
} }
else else
{ {
@ -68,7 +67,7 @@ public class PlcApi
{ {
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds) if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{ {
return plcToHost.RadarStatesOut.Value == 1000 ? true : false; return PlcMgr.PlcToHostData.RadarStatesOut.Value == 1000 ? true : false;
} }
else else
{ {
@ -85,13 +84,8 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool WriteEntranceLamp(int data) public static bool WriteEntranceLamp(int data)
{ {
if (master != null) return PlcMgr.WriteEntranceLamp((byte)data);
{
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.LightIn.Value = (ushort)data;
return master.WriteValue(writeHostToPlc.LightIn);
}
return false;
} }
/// <summary> /// <summary>
@ -103,12 +97,12 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool WriteExistLamp(int data) public static bool WriteExistLamp(int data)
{ {
if (master != null) /*if (master != null)
{ {
HostToPlc writeHostToPlc = new HostToPlc(); HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.LightOut.Value = (ushort)data; writeHostToPlc.LightOut.Value = (ushort)data;
return master.WriteValue(writeHostToPlc.LightIn); return master.WriteValue(writeHostToPlc.LightIn);
} }*/
return false; return false;
} }
@ -120,7 +114,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool DistributeSelectPack(string inBinNo, string outBinNo) public static bool DistributeSelectPack(string inBinNo, string outBinNo)
{ {
if (master != null) /*if (master != null)
{ {
HostToPlc writeHostToPlc = new HostToPlc(); HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.EntrySelection.Value = Convert.ToUInt16(inBinNo); writeHostToPlc.EntrySelection.Value = Convert.ToUInt16(inBinNo);
@ -128,7 +122,7 @@ public class PlcApi
bool write1 = master.WriteValue(writeHostToPlc.EntrySelection); bool write1 = master.WriteValue(writeHostToPlc.EntrySelection);
bool write2 = master.WriteValue(writeHostToPlc.ExitSelection); bool write2 = master.WriteValue(writeHostToPlc.ExitSelection);
return write1 && write2; return write1 && write2;
} }*/
return false; return false;
} }
@ -139,7 +133,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool StartSwapping() public static bool StartSwapping()
{ {
if (master != null) /*if (master != null)
{ {
if (plcToHost.TaskType.Value == 0)//是否允许换电 if (plcToHost.TaskType.Value == 0)//是否允许换电
return false; return false;
@ -150,7 +144,7 @@ public class PlcApi
bool write1 = master.WriteValue(writeHostToPlc.TaskType); bool write1 = master.WriteValue(writeHostToPlc.TaskType);
bool write2 = master.WriteValue(writeHostToPlc.TaskEnablement); bool write2 = master.WriteValue(writeHostToPlc.TaskEnablement);
return write1 && write2; return write1 && write2;
} }*/
return false; return false;
} }
@ -170,10 +164,10 @@ public class PlcApi
/// <returns>6未连接</returns> /// <returns>6未连接</returns>
public static int ReadPlcTaskStatus() public static int ReadPlcTaskStatus()
{ {
if (master != null) /*if (master != null)
{ {
return plcToHost.TaskType.Value; return plcToHost.TaskType.Value;
} }*/
return (-1); return (-1);
} }

@ -29,7 +29,7 @@ public class SwapDoneState : IState
public StateResult Handle(SwappingStateMachine machine) public StateResult Handle(SwappingStateMachine machine)
{ {
//更新换电订单 //更新换电订单
machine.SwapOrder.SwapResult = machine.SwapStatus; machine.SwapOrder!.SwapResult = machine.SwapStatus;
machine.SwapOrder.SwapEndTime = DateTime.Now; machine.SwapOrder.SwapEndTime = DateTime.Now;
machine.SwapOrder.FailReason = machine.SwapFailReason; machine.SwapOrder.FailReason = machine.SwapFailReason;
_swapOrderRepository.Update(machine.SwapOrder); _swapOrderRepository.Update(machine.SwapOrder);
@ -79,7 +79,7 @@ public class SwapDoneState : IState
{ {
//查询车辆锁止状态 //查询车辆锁止状态
Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo(); Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo();
if (carInfo.Result.HeartBeatMsg.LockStatus == 2) if (carInfo.Result.HeartBeatMsg!.LockStatus == 2)
{ {
//设置出口的是绿灯 //设置出口的是绿灯
if (PlcApi.WriteExistLamp(1000)) if (PlcApi.WriteExistLamp(1000))
@ -95,7 +95,7 @@ public class SwapDoneState : IState
_swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelLockFlag, _swapOrderStepService.InsertSwapStepForSwapMain(InfoEnum.BusinessSwappingStep.VelLockFlag,
machine.StepSort++, machine.SwapOrder.Sn); machine.StepSort++, machine.SwapOrder!.Sn);
} }
} }
} }
@ -113,7 +113,7 @@ public class SwapDoneState : IState
return Invoker.Invoke("wait exist radar", 1000, 5, machine.IsCanceled, return Invoker.Invoke("wait exist radar", 1000, 5, machine.IsCanceled,
() => machine.RadarOutFlag, () => () => machine.RadarOutFlag, () =>
{ {
if (!PlcApi.EntranceRadar()) if (!PlcApi.ExitRadar())
{ {
_log.Info("exist radar false"); _log.Info("exist radar false");
} }

@ -0,0 +1,27 @@
using HybirdFrameworkDriver.ModbusTcpMaster;
using HybirdFrameworkServices.Plc;
namespace Service.Plc;
public abstract class PlcMgr
{
public static ModbusTcpMaster ModbusTcpMaster;
public static readonly HostToPlc HostToPlcData = new HostToPlc();
public static readonly PlcToHost PlcToHostData = new PlcToHost();
public static readonly PlcFault PlcFaultData = new PlcFault();
/// <summary>
/// 写入口灯
/// 红灯1020
/// 绿灯1000
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static bool WriteEntranceLamp(byte value)
{
HostToPlcData.LightIn.Value = value;
return ModbusTcpMaster.WriteValue(HostToPlcData.LightIn);
}
}
Loading…
Cancel
Save