plc心跳状态修改

master
CZ 5 months ago
parent 43b99fbf1e
commit e6a01ea2c1

@ -0,0 +1,94 @@
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 * 2;
}
private static bool heart = false;
public BinInfoRepository BinInfoRepository { get; set; }
public void Handle()
{
if (PlcMgr.PlcClient != null)
{
heart = !heart;
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.ProtocolVersion1.Value = 2;
writeHostToPlc.ProtocolVersion2.Value = 0;
writeHostToPlc.ProtocolVersion3.Value = 1;
writeHostToPlc.CommunicationDiagnosis.Value = (ushort)(heart ? 1 : 0);
writeHostToPlc.Years.Value = (ushort)DateTime.Now.Year;
writeHostToPlc.Month.Value = (ushort)DateTime.Now.Month;
writeHostToPlc.Day.Value = (ushort)DateTime.Now.Day;
writeHostToPlc.Hour.Value = (ushort)DateTime.Now.Hour;
writeHostToPlc.Points.Value = (ushort)DateTime.Now.Minute;
writeHostToPlc.Seconds.Value = (ushort)DateTime.Now.Second;
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 write01 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ProtocolVersion1);
bool write02 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ProtocolVersion2);
bool write03 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ProtocolVersion3);
bool write0 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.CommunicationDiagnosis);
bool write1 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Years);
bool write2 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Month);
bool write3 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Day);
bool write4 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Hour);
bool write5 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Points);
bool write6 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.Seconds);
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);
}
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}

@ -57,8 +57,6 @@ public class PlcClient : ModbusTcpMaster
private void BatchRead(ModbusTcpMaster master) private void BatchRead(ModbusTcpMaster master)
{ {
PlcMgr.SendHear();
var bytes01 = master.BatchReadHolderRegister(1, 115); var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null) if (bytes01 != null)
{ {

@ -259,61 +259,6 @@ public class PlcMgr
private static BinInfoRepository BinInfoRepository = AppInfo.Container.Resolve<BinInfoRepository>(); private static BinInfoRepository BinInfoRepository = AppInfo.Container.Resolve<BinInfoRepository>();
/// <summary>
/// 发送心跳
/// </summary>
/// <returns></returns>
public static bool SendHear()
{
if (PlcClient != null)
{
heart = !heart;
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.ProtocolVersion1.Value = 2;
writeHostToPlc.ProtocolVersion2.Value = 0;
writeHostToPlc.ProtocolVersion3.Value = 1;
writeHostToPlc.CommunicationDiagnosis.Value = (ushort)(heart ? 1 : 0);
writeHostToPlc.Years.Value = (ushort)DateTime.Now.Year;
writeHostToPlc.Month.Value = (ushort)DateTime.Now.Month;
writeHostToPlc.Day.Value = (ushort)DateTime.Now.Day;
writeHostToPlc.Hour.Value = (ushort)DateTime.Now.Hour;
writeHostToPlc.Points.Value = (ushort)DateTime.Now.Minute;
writeHostToPlc.Seconds.Value = (ushort)DateTime.Now.Second;
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 write01 = PlcClient.WriteValue(writeHostToPlc.ProtocolVersion1);
bool write02 = PlcClient.WriteValue(writeHostToPlc.ProtocolVersion2);
bool write03 = PlcClient.WriteValue(writeHostToPlc.ProtocolVersion3);
bool write0 = PlcClient.WriteValue(writeHostToPlc.CommunicationDiagnosis);
bool write1 = PlcClient.WriteValue(writeHostToPlc.Years);
bool write2 = PlcClient.WriteValue(writeHostToPlc.Month);
bool write3 = PlcClient.WriteValue(writeHostToPlc.Day);
bool write4 = PlcClient.WriteValue(writeHostToPlc.Hour);
bool write5 = PlcClient.WriteValue(writeHostToPlc.Points);
bool write6 = PlcClient.WriteValue(writeHostToPlc.Seconds);
bool writeCharge2 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus02);
bool writeCharge3 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus03);
bool writeCharge4 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus04);
bool writeCharge5 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus05);
bool writeCharge6 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus06);
bool writeCharge7 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus07);
bool writeCharge8 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus08);
return write1 && write2 && write3 && write4 && write5 && write6;
}
return true;
}
/// <summary> /// <summary>
/// 查看拍照状态 /// 查看拍照状态
/// </summary> /// </summary>

Loading…
Cancel
Save