using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.AutoTask; using log4net; using Service.Plc.Client; using Service.Plc.Msg; namespace Service.MyTask; [Scope] public class PlcHeartTask : ITask { private static readonly ILog Log = LogManager.GetLogger(typeof(PlcHeartTask)); 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 (PlcMgr.PlcClient != null) { heart = !heart; HostToPlc writeHostToPlc = new HostToPlc(); writeHostToPlc.CommunicationDiagnosis.Value = (ushort)(heart ? 1 : 0); bool write0 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.CommunicationDiagnosis); Log.Info("Plc Start write heart success"); } else Log.Info("Plc Start write heart fail"); } public bool Stoped() { return _stop; } public void Stop() { _stop = true; } public void ResetStop() { _stop = false; } }