diff --git a/Service/Execute/Api/PlcApi.cs b/Service/Execute/Api/PlcApi.cs index cff72bd..cb078bf 100644 --- a/Service/Execute/Api/PlcApi.cs +++ b/Service/Execute/Api/PlcApi.cs @@ -4,6 +4,7 @@ using Service.Charger.Client; using Service.Mgr; using Service.Padar.Client; using Service.PlcAfrica.Client; +using Service.PlcAfrica.Msg; namespace Service.Execute.Api; @@ -81,9 +82,9 @@ public class PlcApi if (PlcAfricaMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo))) { Log.Info($"PlcApi StartSwapping done"); - return PlcAfricaMgr.StartSwap(); + return PlcAfricaMgr.StartSwap(); } - return false; + return PlcAfricaMgr.StationCommandFeedback(); } /// diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index 29cb0e6..4cc2ce0 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -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/Fire/Client/FireClient.cs b/Service/Fire/Client/FireClient.cs index 31b5785..a8e48ae 100644 --- a/Service/Fire/Client/FireClient.cs +++ b/Service/Fire/Client/FireClient.cs @@ -11,7 +11,7 @@ public class FireClient: ModbusTcpMaster public FireClient() { ReadAction = BatchRead; - Ip = "192.168.3.100"; + Ip = "192.168.3.210"; Port = 23; Duration = 1000; AutoReConnect = true; diff --git a/Service/Led/LedClient.cs b/Service/Led/LedClient.cs index 03067db..feb94d0 100644 --- a/Service/Led/LedClient.cs +++ b/Service/Led/LedClient.cs @@ -177,7 +177,7 @@ public class LedClient private static readonly ILog Log = LogManager.GetLogger(typeof(LedClient)); private static Socket? _socket; - private static string _ip = "192.168.3.79"; + private static string _ip = "192.168.3.212"; // private static string _ip = "127.0.0.1"; private static int _port = 10000; diff --git a/Service/MyTask/PlcHeartTask.cs b/Service/MyTask/PlcHeartTask.cs new file mode 100644 index 0000000..2769087 --- /dev/null +++ b/Service/MyTask/PlcHeartTask.cs @@ -0,0 +1,68 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.AutoTask; +using log4net; +using Service.PlcAfrica.Client; +using Service.PlcAfrica.Msg; + +namespace Service.MyTask; + +[Scope] +public class PlcHeartTask : ITask +{ + + private static readonly ILog Log = LogManager.GetLogger("PlcHeart"); + private volatile bool _stop; + + public string Name() + { + return "PlcHeartTask"; + } + + public int Interval() + { + return 1000 * 1; + } + + private static bool heart = false; + + public void Handle() + { + Log.Info("Plc Start write heart"); + if (PlcAfricaMgr.PlcAfricaClient != null && PlcAfricaMgr.PlcAfricaClient.Connected) + { + heart = !heart; + PlcAfricaMsg writeHostToPlc = new PlcAfricaMsg(); + writeHostToPlc.Heart.Value = (ushort)(heart ? 1 : 0); + Log.Info("Plc Start write heart write begin"); + bool write0 = PlcAfricaMgr.PlcAfricaClient.WriteValue(writeHostToPlc.Heart); + Log.Info($"write return {write0}"); + if (!write0) + { + Log.Info("Plc Start write heart write timeout"); + } + else + { + Log.Info("Plc Start write heart write success"); + } + + + } + else + Log.Info("Plc Start write heart fail"); + } + + 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/Padar/Client/PadarMgr.cs b/Service/Padar/Client/PadarMgr.cs index 2a2736e..222bae3 100644 --- a/Service/Padar/Client/PadarMgr.cs +++ b/Service/Padar/Client/PadarMgr.cs @@ -21,8 +21,8 @@ public class PadarMgr { PadarClient client = AppInfo.Container.Resolve(); client.AutoReconnect = true; - //client.InitBootstrap("192.168.3.55", int.Parse("2048")); - client.InitBootstrap("192.168.3.52", int.Parse("2048"), 10,0, 0); + //client.InitBootstrap("192.168.3.55", int.Parse("2048")); + client.InitBootstrap("192.168.3.199", int.Parse("2048"), 10,0, 0); Task.Run(() => { client.Connect(); diff --git a/Service/PlcAfrica/Client/PlcAfricaClient.cs b/Service/PlcAfrica/Client/PlcAfricaClient.cs index 05a9c9d..7e3434c 100644 --- a/Service/PlcAfrica/Client/PlcAfricaClient.cs +++ b/Service/PlcAfrica/Client/PlcAfricaClient.cs @@ -40,8 +40,7 @@ namespace Service.PlcAfrica.Client ModbusDecoder.Decode(bytes01, PlcAfricaMgr.PlcAfricaMsg, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); - - var vv= PlcAfricaMgr.PlcAfricaMsg.PowerChangeMode.Value; + } return resul; diff --git a/Service/PlcAfrica/Client/PlcAfricaMgr.cs b/Service/PlcAfrica/Client/PlcAfricaMgr.cs index f12b45b..c2b81d1 100644 --- a/Service/PlcAfrica/Client/PlcAfricaMgr.cs +++ b/Service/PlcAfrica/Client/PlcAfricaMgr.cs @@ -65,7 +65,7 @@ namespace Service.PlcAfrica.Client public static bool StartSwap() { - if (PlcAfricaClient == null) + if (PlcAfricaClient != null) { PlcAfricaMsg.OperationInstruction.Value = 2; PlcAfricaClient!.WriteValue(PlcAfricaMsg.OperationInstruction); @@ -77,6 +77,11 @@ namespace Service.PlcAfrica.Client return false; } + public static bool StationCommandFeedback() + { + return PlcAfricaMsg.StationCommandFeedback.Value == 2; + } + /// /// 操作指令 /// @@ -179,7 +184,7 @@ namespace Service.PlcAfrica.Client { InBinNo = inBinNo, - OutBinNo = outBinNo, + OutBinNo = inBinNo,//outBinNo, }; byte[] encode = ModelConvert.Encode(distributeTask); @@ -195,7 +200,7 @@ namespace Service.PlcAfrica.Client } //需要将数据转换成byte数组 - OperateResult operateResult = PlcAfricaClient.Write("x=16;111", encode); + OperateResult operateResult = PlcAfricaClient.Write("x=16;7008", encode); return operateResult.IsSuccess; }