using log4net;
using Service.Plc.Client;
namespace Service.Execute.Api;
public class PlcApi
{
private const int TimeSpan = 60;
private static readonly ILog Log = LogManager.GetLogger("PlcApi");
///
/// 数据有效时间。单位秒
///
static int DataTimeSeconds = 2;
///
/// 是否远程模式
///
///
public static bool IsRemote()
{
var isRemote = PlcMgr.IsRemote();
Log.Info($"PlcApi IsRemove resp={isRemote}");
return isRemote;
}
public static bool IsAuto()
{
var isAuto = PlcMgr.IsAuto();
Log.Info($"PlcApi IsRemove resp={isAuto}");
return isAuto;
}
///
/// 入口雷达检测
///
///
public static bool EntranceRadar()
{
var entranceRadar = PlcMgr.EntranceRadar();
Log.Info($"PlcApi EntranceRadar resp={entranceRadar}");
return entranceRadar;
}
///
/// 出口雷达检测
///
///
public static bool ExitRadar()
{
var exitRadar = PlcMgr.ExitRadar();
Log.Info($"PlcApi ExitRadar resp={exitRadar}");
return exitRadar;
}
///
/// 写入口灯
/// 红灯:1020
/// 绿灯:1000
///
///
///
public static bool WriteEntranceLamp(ushort data)
{
Log.Info($"PlcApi writeEntranceLamp start data={data}");
var writeEntranceLamp = PlcMgr.WriteEntranceLamp(data);
Log.Info($"PlcApi writeEntranceLamp resp={writeEntranceLamp}");
return writeEntranceLamp;
}
///
/// 写出口灯
/// 红灯:1020
/// 绿灯:1000
///
///
///
public static bool WriteExistLamp(ushort data)
{
Log.Info($"PlcApi WriteExistLamp start data={data}");
var writeExistLamp = PlcMgr.WriteExistLamp(data);
Log.Info($"PlcApi WriteExistLamp resp={writeExistLamp}");
return writeExistLamp;
}
///
/// 下发选包
///
/// 入仓位,仓位号
/// 出仓位,仓位号
///
public static bool DistributeSelectPack(string inBinNo, string outBinNo)
{
Log.Info($"PlcApi DistributeSelectPack start inBinNo={inBinNo} outBinNo={outBinNo}");
return PlcMgr.DistributeBinNo(inBinNo, outBinNo);
}
///
/// 下发启动换电
///
///
public static bool StartSwapping(string inBinNo, string outBinNo)
{
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
var distributeTask = PlcMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo), 1);
Log.Info($"PlcApi StartSwapping resp={distributeTask}");
return distributeTask;
}
///
/// 读取任务状态
///
///
public static bool ReadTaskStatus(ushort taskNo)
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi ReadTaskStatus param= taskNo={taskNo}");
var readTaskStatus = PlcMgr.ReadTaskStatus(taskNo);
Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}");
return readTaskStatus;
}
///
/// plc上使能 1换电,2移仓,3消防
///
///
public static bool HoldOn(int taskType)
{
Log.Info($"PlcApi start HoldOn ");
var holdOn = PlcMgr.HoldOn(taskType);
Log.Info($"PlcApi HoldOn resp={holdOn}");
return holdOn;
}
///
/// 查看拍照状态
///
///
public static ushort ChannelStatus()
{
Log.Info($"PlcApi start ChannelStatus ");
PlcMgr.ResetPlc();
var channelStatus = PlcMgr.ChannelStatus();
Log.Info($"PlcApi ChannelStatus resp= {channelStatus}");
return channelStatus;
}
///
/// 换电过程状态
/// 0:无效值
/// 1000:准备中(Not Ready)
/// 1001:待机中(Ready)
/// 1002:电池拆卸中
/// 1003:电池入库搬运中
/// 1004:电池出库搬运中
/// 1005:电池安装中
/// 1006:电池安装完成
/// 1007:航车回归至安全位置
/// 1008: 缓存-放仓位, 移仓状态
///
public static int ReadSwapStatus()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi start ReadSwapStatus ");
var readPlcTaskStatus = PlcMgr.ReadSwapStatus();
Log.Info($"PlcApi ReadSwapStatus resp= {readPlcTaskStatus}");
return readPlcTaskStatus;
}
///
/// 消防任务状态
/// 0:等待消防任务
/// 1000:消防任务 执行中
/// 1001:消防任务 正常完成
/// 1009:消防任务 出现异常
///
public static int ReadFireStatus()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi start ReadFireStatus ");
var readPlcTaskStatus = PlcMgr.ReadFireStatus();
Log.Info($"PlcApi ReadFireStatus resp= {readPlcTaskStatus}");
return readPlcTaskStatus;
}
///
/// 移仓状态
/// 0:等待移仓任务
/// 1001:移仓任务 执行中
/// 1002:移仓任务 正常完成
/// 1009:移仓任务 出现异常
///
public static int ReadMoveStatus()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi start ReadMoveStatus ");
var readPlcTaskStatus = PlcMgr.ReadMoveStatus();
Log.Info($"PlcApi ReadMoveStatus resp= {readPlcTaskStatus}");
return readPlcTaskStatus;
}
}