|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 数据有效时间。单位秒
|
|
|
/// </summary>
|
|
|
static int DataTimeSeconds = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否远程模式
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 入口雷达检测
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static bool EntranceRadar()
|
|
|
{
|
|
|
var entranceRadar = PlcMgr.EntranceRadar();
|
|
|
Log.Info($"PlcApi EntranceRadar resp={entranceRadar}");
|
|
|
return entranceRadar;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 出口雷达检测
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static bool ExitRadar()
|
|
|
{
|
|
|
var exitRadar = PlcMgr.ExitRadar();
|
|
|
Log.Info($"PlcApi ExitRadar resp={exitRadar}");
|
|
|
return exitRadar;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 写入口灯
|
|
|
/// 红灯:1020
|
|
|
/// 绿灯:1000
|
|
|
/// </summary>
|
|
|
/// <param name="data"></param>
|
|
|
/// <returns></returns>
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 写出口灯
|
|
|
/// 红灯:1020
|
|
|
/// 绿灯:1000
|
|
|
/// </summary>
|
|
|
/// <param name="data"></param>
|
|
|
/// <returns></returns>
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下发选包
|
|
|
/// </summary>
|
|
|
/// <param name="inBinNo">入仓位,仓位号</param>
|
|
|
/// <param name="outBinNo">出仓位,仓位号</param>
|
|
|
/// <returns></returns>
|
|
|
public static bool DistributeSelectPack(string inBinNo, string outBinNo)
|
|
|
{
|
|
|
Log.Info($"PlcApi DistributeSelectPack start inBinNo={inBinNo} outBinNo={outBinNo}");
|
|
|
return PlcMgr.DistributeBinNo(inBinNo, outBinNo);
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下发启动换电
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
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), 2);
|
|
|
|
|
|
Log.Info($"PlcApi StartSwapping resp={distributeTask}");
|
|
|
return distributeTask;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取任务状态
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取任务状态
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static bool ReadTaskStatusReset()
|
|
|
{
|
|
|
PlcMgr.ResetPlc();
|
|
|
Log.Info($"PlcApi ReadTaskStatus param= taskNo={0}");
|
|
|
var readTaskStatus = PlcMgr.ReadTaskStatus(0);
|
|
|
Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}");
|
|
|
return readTaskStatus;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// plc上使能
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static bool HoldOn()
|
|
|
{
|
|
|
Log.Info($"PlcApi start HoldOn ");
|
|
|
var holdOn = PlcMgr.HoldOn();
|
|
|
Log.Info($"PlcApi HoldOn resp={holdOn}");
|
|
|
return holdOn;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看拍照状态
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static ushort[] ChannelStatus()
|
|
|
{
|
|
|
Log.Info($"PlcApi start ChannelStatus ");
|
|
|
PlcMgr.ResetPlc();
|
|
|
ushort[] channelStatus=new ushort[2];
|
|
|
channelStatus[0] = PlcMgr.ChannelStatus(1);
|
|
|
channelStatus[1] = PlcMgr.ChannelStatus(2);
|
|
|
Log.Info($"PlcApi ChannelStatus resp= {channelStatus}");
|
|
|
return channelStatus;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读plc任务状态
|
|
|
/// <para>0:无效值</para>
|
|
|
/// <para>1000:准备中(Not Ready)</para>
|
|
|
/// <para>1001:待机中(Ready)</para>
|
|
|
/// <para>1002:电池拆卸中</para>
|
|
|
/// <para>1003:电池入库搬运中</para>
|
|
|
/// <para>1004:电池出库搬运中</para>
|
|
|
/// <para>1005:电池安装中</para>
|
|
|
/// <para>1006:电池安装完成</para>
|
|
|
/// <para>1007:航车回归至安全位置</para>
|
|
|
/// <para>1008: 缓存-放仓位, 移仓状态</para>
|
|
|
/// <para>1100:消防任务 执行中</para>
|
|
|
/// <para>1101:消防任务 出现异常</para>
|
|
|
/// <para>1200:移仓任务 执行中</para>
|
|
|
/// <para>1201:移仓任务 出现异常</para>
|
|
|
/// <para>9000:任务完成</para>
|
|
|
/// </summary>
|
|
|
/// <returns>6未连接</returns>
|
|
|
public static int ReadPlcTaskStatus()
|
|
|
{
|
|
|
PlcMgr.ResetPlc();
|
|
|
Log.Info($"PlcApi start ReadPlcTaskStatus ");
|
|
|
var readPlcTaskStatus = PlcMgr.ReadPlcTaskStatus();
|
|
|
Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}");
|
|
|
return readPlcTaskStatus;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读实体按钮状态
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static bool ReadPhysicalButtonState()
|
|
|
{
|
|
|
PlcMgr.ResetPlc();
|
|
|
Log.Info($"PlcApi start ReadPhysicalButtonState ");
|
|
|
var readPhysicalButtonState = PlcMgr.PhysicalButtonStateRadar();
|
|
|
Log.Info($"PlcApi ReadPhysicalButtonState resp= {readPhysicalButtonState}");
|
|
|
return readPhysicalButtonState;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|