diff --git a/Service/Execute/Step/CarCtrlState.cs b/Service/Execute/Step/CarCtrlState.cs index 8235a3d..d810f19 100644 --- a/Service/Execute/Step/CarCtrlState.cs +++ b/Service/Execute/Step/CarCtrlState.cs @@ -57,6 +57,7 @@ public class CarCtrlState : IState { //查询车辆锁止状态 Task carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin); + carInfo.Wait(); var resultHeartBeatMsg = carInfo.Result.CarStatus; if (resultHeartBeatMsg?.LockStatus == 1 || machine.ManualConfirmCarUnlockFlag) { diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index 4cc2ce0..1c47d7f 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -40,7 +40,7 @@ public class DoSwappingState : IState //记录为 换电任务 - + //下发启动换电 InvokeStatus startSwapping = StartSwapping(machine); if (startSwapping != InvokeStatus.Done) @@ -132,9 +132,9 @@ public class DoSwappingState : IState return Invoker.Invoke("StartSwapping", 1000, 5, machine.IsCanceled, () => machine.StartSwappingFlag, () => { + //PlcApi.CarStatus(1); if (PlcAfricaMgr.PlcAfricaClient.IsTaskFree()) { - PlcApi.CarStatus(1); var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, machine.SwapOrderBatteryInfo.UpBinInfo.No); @@ -224,7 +224,7 @@ public class DoSwappingState : IState () => machine.InstallNewBatteryFlag, () => { // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed()); - // LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPack.GetLed()); + // LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPack.GetLed()); machine.InstallNewBatteryFlag =PlcApi.ReadAction() >29 ; @@ -256,7 +256,7 @@ public class DoSwappingState : IState return Invoker.Invoke("plc Pack Finish", 500, 5, machine.IsCanceled, () => machine.FinishNewBatteryFlag, () => { - if (PlcApi.ReadAction()==44 && (PlcApi.RobotWorkFinish() || PlcApi.RobotReady())) + if (PlcApi.ReadAction()==44 || PlcApi.RobotWorkFinish() || PlcApi.RobotReady()) { machine.FinishNewBatteryFlag = true; machine.BusinessSwappingForCloudState = diff --git a/Service/Execute/Step/StationReadyState.cs b/Service/Execute/Step/StationReadyState.cs index aefab45..8158fc8 100644 --- a/Service/Execute/Step/StationReadyState.cs +++ b/Service/Execute/Step/StationReadyState.cs @@ -46,7 +46,7 @@ public class StationReadyState : IState _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.Idel, machine); - LedClient.SendMsgByKey(InfoEnum.SwapInfo.WelcomeInfo.GetLed()); + LedClient.SendMsgByKey(InfoEnum.SwapInfo.WelcomeInfo.GetLed()); Thread.Sleep(2000); ////开启雷达 var beginRadar = ControlRadar(machine, 1); @@ -175,7 +175,8 @@ public class StationReadyState : IState public InvokeStatus ControlRadar(SwappingStateMachine machine, byte flag) { - return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => PadarMgr._PadarClient?.CarState > 0 + return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => + PadarMgr._PadarClient?.CarState > 0 || machine.ManualSkipRadar, () => { PadarMgr._PadarClient?.PadarControl(flag); }); } @@ -269,18 +270,18 @@ public class StationReadyState : IState // Task open = RfidApi.Connect(); LedClient.SendMsgByKey(InfoEnum.SwapInfo.diparkir.GetLed()); machine.RfidConnectFlag = true; - Task beginRead = RfidApi.BeginRead(); - beginRead.Wait(); - if (!beginRead.Result) - { - _log.Info("begin read rfid error"); - } - else - { - machine.ExceptionReason = ExceptionReason.None; - _log.Info("begin read done"); - machine.BeginRfidReadFlag = true; - } + Task beginRead = RfidApi.BeginRead(); + beginRead.Wait(); + if (!beginRead.Result) + { + _log.Info("begin read rfid error"); + } + else + { + machine.ExceptionReason = ExceptionReason.None; + _log.Info("begin read done"); + machine.BeginRfidReadFlag = true; + } }, () => { diff --git a/Service/MyTask/WritePlcTask.cs b/Service/MyTask/WritePlcTask.cs new file mode 100644 index 0000000..74629f3 --- /dev/null +++ b/Service/MyTask/WritePlcTask.cs @@ -0,0 +1,81 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.AutoTask; +using log4net; +using Service.Execute; +using Service.Execute.Api; +using Service.PlcAfrica.Client; +using Service.PlcAfrica.Msg; + +namespace Service.MyTask; + +[Scope] +public class WritePlcTask : ITask +{ + private static readonly ILog Log = LogManager.GetLogger("WritePlcTask"); + private volatile bool _stop; + + private PlcAfricaMsg PlcAfricaMsg = new PlcAfricaMsg(); + + public string Name() + { + return "WritePlcTask"; + } + + public int Interval() + { + return 1000 * 1; + } + + private static bool heart = false; + + public void Handle() + { + Log.Info("Plc Start write"); + PlcAfricaMsg.TboxUnlock.Value = 0; + if (StationSoftMgr.SwappingStateMachine != null) + { + var swappingStateMachine = StationSoftMgr.SwappingStateMachine; + if (swappingStateMachine.BoxConnectFlag) //TBOX + { + var carInfo = TBoxApi.GetCarInfo(swappingStateMachine.RfidReadModel.VelVin); + carInfo.Wait(); + if (swappingStateMachine.BoxCarInfoModel != null && carInfo != null) + { + PlcAfricaMsg.TboxUnlock.Value = (ushort)carInfo.Result?.CarStatus?.LockStatus; + bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock); + Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}"); + } + else + { + bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock); + Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}"); + } + } + else + { + bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock); + Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}"); + } + } + else + { + bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock); + Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}"); + } + } + + 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/PlcAfrica/Client/PlcAfricaMgr.cs b/Service/PlcAfrica/Client/PlcAfricaMgr.cs index c2b81d1..de36a2e 100644 --- a/Service/PlcAfrica/Client/PlcAfricaMgr.cs +++ b/Service/PlcAfrica/Client/PlcAfricaMgr.cs @@ -155,7 +155,7 @@ namespace Service.PlcAfrica.Client if (PlcAfricaClient == null) { PlcAfricaMsg.TboxUnlock.Value = cmd; - return PlcAfricaClient!.WriteValue(PlcAfricaMsg.TboxUnlock); + return PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock); } diff --git a/Service/PlcAfrica/Msg/PlcAfricaMsg.cs b/Service/PlcAfrica/Msg/PlcAfricaMsg.cs index b428140..fab2ec1 100644 --- a/Service/PlcAfrica/Msg/PlcAfricaMsg.cs +++ b/Service/PlcAfrica/Msg/PlcAfricaMsg.cs @@ -322,16 +322,17 @@ public class PlcAfricaMsg /// 加载机1落座传感器1 0-不在位,1-在位 /// public ModbusProperty Loader1SeatSensor1 {get;set;}= new(49043,start:0,length:1,type:ModbusDataType.Bit); - /// - /// 加载机1落座传感器2 + /// 加载机2落座传感器1 /// - public ModbusProperty Loader1SeatSensor2 {get;set;}= new(49043,start:1,length:1,type:ModbusDataType.Bit); + public ModbusProperty Loader2SeatSensor1 {get;set;}= new(49043,start:1,length:1,type:ModbusDataType.Bit); + + /// - /// 加载机2落座传感器1 + /// 加载机1落座传感器2 /// - public ModbusProperty Loader2SeatSensor1 {get;set;}= new(49043,start:1,length:1,type:ModbusDataType.Bit); + public ModbusProperty Loader1SeatSensor2 {get;set;}= new(49043,start:1,length:1,type:ModbusDataType.Bit); /// /// 加载机2落座传感器2 @@ -596,4 +597,11 @@ public class PlcAfricaMsg /// public ModbusProperty TransferBinSeatSensor2 {get;set;}= new(49438,start:1,length:1,type:ModbusDataType.Bit); + /// + /// 电池充电状态 + /// + public ModbusProperty ChargerState1 {get;set;}= new(49437); + public ModbusProperty ChargerState2 {get;set;}= new(49437); + public ModbusProperty ChargerState3 {get;set;}= new(49437); + public ModbusProperty ChargerState4 {get;set;}= new(49437); } \ No newline at end of file