diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index 4318a35..29cb0e6 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -17,6 +17,7 @@ using Service.Execute.Utils; using Service.Init; using Service.Led; using Service.Padar.Client; +using Service.PlcAfrica.Client; using Service.Sound.SoundClient; namespace Service.Execute.Step; @@ -67,7 +68,7 @@ public class DoSwappingState : IState { return SwappingStateMachine.ReturnWithInvokeErr(packFinish, ExceptionReason.None); } - ClientMgr.PlcClient.ResetTaskNo(); + PlcAfricaMgr.PlcAfricaClient.ResetTaskNo(); return new StateResult() { @@ -131,10 +132,9 @@ public class DoSwappingState : IState return Invoker.Invoke("StartSwapping", 1000, 5, machine.IsCanceled, () => machine.StartSwappingFlag, () => { - if (ClientMgr.PlcClient.IsTaskFree()) + if (PlcAfricaMgr.PlcAfricaClient.IsTaskFree()) { PlcApi.CarStatus(1); - // ClientMgr.PlcClient.ExChangeTaskNo(1); var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, machine.SwapOrderBatteryInfo.UpBinInfo.No); @@ -151,7 +151,7 @@ public class DoSwappingState : IState //查詢當前任務狀態是否被更改 if (startSwapping) { - ClientMgr.PlcClient.ExChangeTaskNo(1); + PlcAfricaMgr.PlcAfricaClient.ExChangeTaskNo(1); machine.SwapOrder.SwapBeginTime = DateTime.Now; _CommonMgr.UpdateSwapOrder(machine); machine.SwapStatus = 0; diff --git a/Service/PlcAfrica/Client/PlcAfricaClient.cs b/Service/PlcAfrica/Client/PlcAfricaClient.cs index 4a61055..05a9c9d 100644 --- a/Service/PlcAfrica/Client/PlcAfricaClient.cs +++ b/Service/PlcAfrica/Client/PlcAfricaClient.cs @@ -15,6 +15,7 @@ namespace Service.PlcAfrica.Client [Scope] public class PlcAfricaClient : ModbusTcpMaster { + private long TaskNo = 0; public PlcAfricaClient() { ReadAction = BatchRead; @@ -45,5 +46,28 @@ namespace Service.PlcAfrica.Client return resul; } + + //修改当前任务 + public void ExChangeTaskNo(long taskNo) + { + Interlocked.Exchange(ref TaskNo, taskNo); + } + + //重置当前任务 + public void ResetTaskNo() + { + Interlocked.Exchange(ref TaskNo, 0); + } + + public bool IsTaskFree() + { + return ReadTaskNo() == 0l; + } + + //读取当前任务 + public long ReadTaskNo() + { + return Interlocked.Read(ref TaskNo); + } } }