|
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkCore.AutoTask;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
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 BinInfoRepository BinInfoRepository { get; set; }
|
|
|
|
|
|
|
|
|
|
public void Handle()
|
|
|
|
|
{
|
|
|
|
|
Log.Info("Plc start write heart");
|
|
|
|
|
if (PlcMgr.PlcClient != null)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("Plc write connect and satrt set value");
|
|
|
|
|
heart = !heart;
|
|
|
|
|
HostToPlc writeHostToPlc = new HostToPlc();
|
|
|
|
|
writeHostToPlc.CommunicationDiagnosis.Value = (ushort)(heart ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
var lstBinInfo = BinInfoRepository.Query();
|
|
|
|
|
writeHostToPlc.ChargingStatus02.Value = (short)(lstBinInfo[1].ChargeStatus == 1 ? 1010 : 1000);
|
|
|
|
|
writeHostToPlc.ChargingStatus03.Value = (short)(lstBinInfo[2].ChargeStatus == 1 ? 1010 : 1000);
|
|
|
|
|
writeHostToPlc.ChargingStatus04.Value = (short)(lstBinInfo[3].ChargeStatus == 1 ? 1010 : 1000);
|
|
|
|
|
writeHostToPlc.ChargingStatus05.Value = (short)(lstBinInfo[4].ChargeStatus == 1 ? 1010 : 1000);
|
|
|
|
|
writeHostToPlc.ChargingStatus06.Value = (short)(lstBinInfo[5].ChargeStatus == 1 ? 1010 : 1000);
|
|
|
|
|
writeHostToPlc.ChargingStatus07.Value = (short)(lstBinInfo[6].ChargeStatus == 1 ? 1010 : 1000);
|
|
|
|
|
writeHostToPlc.ChargingStatus08.Value = (short)(lstBinInfo[7].ChargeStatus == 1 ? 1010 : 1000);
|
|
|
|
|
|
|
|
|
|
bool write0 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.CommunicationDiagnosis);
|
|
|
|
|
bool writeCharge2 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus02);
|
|
|
|
|
bool writeCharge3 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus03);
|
|
|
|
|
bool writeCharge4 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus04);
|
|
|
|
|
bool writeCharge5 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus05);
|
|
|
|
|
bool writeCharge6 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus06);
|
|
|
|
|
bool writeCharge7 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus07);
|
|
|
|
|
bool writeCharge8 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus08);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|