心跳状态修改

zw
CZ 1 month ago
parent 36ca29a042
commit 9bee050d1c

@ -0,0 +1,80 @@
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 PlcChargerStatusTask: ITask
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcChargerStatusTask));
private volatile bool _stop;
public string Name()
{
return "PlcChargerStatusTask";
}
public int Interval()
{
return 1000 * 1;
}
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");
HostToPlc writeHostToPlc = new HostToPlc();
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);
ushort[] lstUsort = new[]
{
(ushort)(writeHostToPlc.ChargingStatus02.Value = (short)(lstBinInfo[1].ChargeStatus == 1 ? 1010 : 1000)),
(ushort)(writeHostToPlc.ChargingStatus03.Value = (short)(lstBinInfo[2].ChargeStatus == 1 ? 1010 : 1000)),
(ushort)(writeHostToPlc.ChargingStatus04.Value = (short)(lstBinInfo[3].ChargeStatus == 1 ? 1010 : 1000)),
(ushort)(writeHostToPlc.ChargingStatus05.Value = (short)(lstBinInfo[4].ChargeStatus == 1 ? 1010 : 1000)),
(ushort)(writeHostToPlc.ChargingStatus06.Value = (short)(lstBinInfo[5].ChargeStatus == 1 ? 1010 : 1000)),
(ushort)(writeHostToPlc.ChargingStatus07.Value = (short)(lstBinInfo[6].ChargeStatus == 1 ? 1010 : 1000)),
(ushort)(writeHostToPlc.ChargingStatus08.Value = (short)(lstBinInfo[7].ChargeStatus == 1 ? 1010 : 1000)),
};
PlcMgr.PlcClient.Write("x=3;31", lstUsort);
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;
}
}

@ -1,18 +1,17 @@
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
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
public class PlcHeartTask : ITask
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcHeartTask));
private volatile bool _stop;
public string Name()
{
return "PlcHeartTask";
@ -23,47 +22,23 @@ public class PlcHeartTask: ITask
return 1000 * 1;
}
private static bool heart = false;
public BinInfoRepository BinInfoRepository { get; set; }
public void Handle()
{
Log.Info("Plc start write heart");
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");
Log.Info("Plc Start write heart success");
}
else
{
Log.Info("Plc write not connect");
}
Log.Info("Plc Start write heart fail");
}
public bool Stoped()
{
return _stop;

Loading…
Cancel
Save