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.
111 lines
3.5 KiB
111 lines
3.5 KiB
using Entity.DbModel.Station;
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using HybirdFrameworkCore.AutoTask;
|
|
using log4net;
|
|
using Repository.Station;
|
|
using Service.Execute;
|
|
using Service.Execute.Api;
|
|
using Service.PlcAfrica.Client;
|
|
using Service.PlcAfrica.Msg;
|
|
|
|
namespace Service.MyTask;
|
|
|
|
[Scope]
|
|
public class WritePlcTask : ITask
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger("WritePlcTask");
|
|
private volatile bool _stop;
|
|
|
|
private PlcAfricaMsg PlcAfricaMsg = new PlcAfricaMsg();
|
|
|
|
public BinInfoRepository BinInfoRepository { get; set; }
|
|
|
|
public WritePlcTask(BinInfoRepository binInfoRepository)
|
|
{
|
|
BinInfoRepository = binInfoRepository;
|
|
}
|
|
|
|
public string Name()
|
|
{
|
|
return "WritePlcTask";
|
|
}
|
|
|
|
public int Interval()
|
|
{
|
|
return 1000 * 1;
|
|
}
|
|
|
|
private static bool heart = false;
|
|
|
|
public void Handle()
|
|
{
|
|
Log.Info("Plc Start write");
|
|
|
|
PlcAfricaMsg.TboxUnlock.Value = 0;
|
|
if (PlcAfricaMgr.PlcAfricaClient.Connected)
|
|
{
|
|
#region 写车辆解锁状态
|
|
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)
|
|
{
|
|
PlcAfricaMsg.TboxUnlock.Value = (ushort)carInfo.Result?.CarStatus?.LockStatus;
|
|
bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock);
|
|
Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}");
|
|
}
|
|
else
|
|
{
|
|
bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock);
|
|
Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock);
|
|
Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool writeCharge = PlcAfricaMgr.PlcAfricaClient.WriteValue(PlcAfricaMsg.TboxUnlock);
|
|
Log.Info($"写锁止状态:{PlcAfricaMsg.TboxUnlock.Value}");
|
|
}
|
|
#endregion
|
|
|
|
#region 写电池充电状态
|
|
|
|
List<BinInfo> lstBinInfo = BinInfoRepository.Query();
|
|
ushort[] lstUsort1 = new[]
|
|
{
|
|
(ushort)(lstBinInfo.Where(i => i.No == "1").ToList().First().ChargeStatus == 1 ? 1 : 2),
|
|
(ushort)(lstBinInfo.Where(i => i.No == "2").ToList().First().ChargeStatus == 1 ? 1 : 2),
|
|
(ushort)(lstBinInfo.Where(i => i.No == "3").ToList().First().ChargeStatus == 1 ? 1 : 2),
|
|
};
|
|
PlcAfricaMgr.PlcAfricaClient.Write("x=3;49437", lstUsort1);
|
|
|
|
#endregion
|
|
}
|
|
|
|
Log.Info("Plc Finish write");
|
|
}
|
|
|
|
public bool Stoped()
|
|
{
|
|
return _stop;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
_stop = true;
|
|
}
|
|
|
|
public void ResetStop()
|
|
{
|
|
_stop = false;
|
|
}
|
|
} |