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.

125 lines
4.3 KiB

using Autofac;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
using HybirdFrameworkCore.Utils;
using HybirdFrameworkDriver.ModbusTcpMaster;
using log4net;
using Repository.Station;
using Service.Execute;
using Service.Execute.Api;
using Service.Execute.Utils;
using Service.Plc.Client;
using Service.Plc.Msg;
namespace Service.MyTask;
[Scope]
public class PlcHeartTask : ITask
{
public PlcHeartTask(BinInfoRepository binInfoRepository)
{
BinInfoRepository = binInfoRepository;
}
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcHeartTask));
private volatile bool _stop;
public string Name()
{
return "PlcHeartTask";
}
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();
List<BinInfo> lstBinInfo = BinInfoRepository.Query();
ushort[] lstUsort1 =new []
{
(ushort)(lstBinInfo[0].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[1].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[2].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[3].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[4].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[5].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[6].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[7].ChargeStatus == 1 ? 1010 : 1000),
};
ushort[] lstUsort2 = new[]
{
(ushort)(lstBinInfo[10].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[11].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[12].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[13].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[14].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[15].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[16].ChargeStatus == 1 ? 1010 : 1000),
(ushort)(lstBinInfo[17].ChargeStatus == 1 ? 1010 : 1000),
};
PlcMgr.PlcClient.Write("x=3;21",lstUsort1);
PlcMgr.PlcClient.Write("x=3;41",lstUsort2);
{
//这里根据换电任务状态写车辆停车状态
writeHostToPlc.VehicleParkingStatus.Value = 0;
if (StationSoftMgr.SwappingStateMachine != null)
{
var swappingStateMachine = StationSoftMgr.SwappingStateMachine;
if (swappingStateMachine.BoxConnectFlag) //TBOX
{
var carInfo = TBoxApi.GetCarInfo(swappingStateMachine.RfidReadModel.VelVin);
carInfo.Wait();
if (swappingStateMachine.BoxCarInfoModel != null && carInfo != null)
{
writeHostToPlc.VehicleParkingStatus.Value = //2;
carInfo.Result?.HeartBeatMsg?.handbrake == 1 ? (ushort)2 : (ushort)0;
bool writeCharge = PlcMgr.PlcClient.WriteValue(writeHostToPlc.VehicleParkingStatus);
}
else
{
bool writeCharge = PlcMgr.PlcClient.WriteValue(writeHostToPlc.VehicleParkingStatus);
}
}
else
{
bool writeCharge = PlcMgr.PlcClient.WriteValue(writeHostToPlc.VehicleParkingStatus);
}
}
}
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;
}
}