You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB

using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
using HybirdFrameworkCore.Utils;
using HybirdFrameworkDriver.ModbusTcpMaster;
using log4net;
using Repository.Station;
using Service.Plc.Client;
using Service.Plc.Msg;
namespace Service.MyTask;
[Scope]
public class PlcHeartAddTask: ITask
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcHeartAddTask));
private volatile bool _stop;
public string Name()
{
return "PlcHeartAddTask";
}
public int Interval()
{
return 1000 * 1;
}
private static bool heart = false;
public void Handle()
{
Log.Info("Plc start write heart");
if (PlcMgr.PlcClient != null)
{
Log.Info("Plc write connect and satrt set value");
HostToPlc writeHostToPlc = new HostToPlc();
heart = !heart;
writeHostToPlc.CommunicationDiagnosis.Value = (ushort)(heart ? 1 : 0);
bool write0 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.CommunicationDiagnosis);
Log.Info("Plc write finish");
}
else
{
Log.Info("Plc write not connect");
}
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}