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.
56 lines
1.2 KiB
56 lines
1.2 KiB
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;
|
|
}
|
|
} |