|
|
|
|
using HybirdFrameworkDriver.ModbusTcpMaster;
|
|
|
|
|
using log4net;
|
|
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
|
|
|
|
using Service.Cloud.Msg.Cloud.Req;
|
|
|
|
|
using Service.Init.Entity;
|
|
|
|
|
using Service.Plc;
|
|
|
|
|
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($"plc IsRemove resp={isRemote}");
|
|
|
|
|
return isRemote;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsAuto()
|
|
|
|
|
{
|
|
|
|
|
var isAuto = PlcMgr.IsAuto();
|
|
|
|
|
Log.Info($"plc IsRemove resp={isAuto}");
|
|
|
|
|
return isAuto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 入口雷达检测
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool EntranceRadar()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return PlcMgr.EntranceRadar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 出口雷达检测
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool ExitRadar()
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.ExitRadar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入口灯
|
|
|
|
|
/// 红灯:1020
|
|
|
|
|
/// 绿灯:1000
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool WriteEntranceLamp(ushort data)
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.WriteEntranceLamp(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写出口灯
|
|
|
|
|
/// 红灯:1020
|
|
|
|
|
/// 绿灯:1000
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool WriteExistLamp(ushort data)
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.WriteExistLamp(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下发选包
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="inBinNo">入仓位,仓位号</param>
|
|
|
|
|
/// <param name="outBinNo">出仓位,仓位号</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool DistributeSelectPack(string inBinNo, string outBinNo)
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.DistributeBinNo(inBinNo, outBinNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下发启动换电
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool StartSwapping(string inBinNo, string outBinNo)
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取任务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool ReadTaskStatus(ushort taskNo)
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.ReadTaskStatus(taskNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// plc上使能
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool HoldOn()
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.HoldOn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查看拍照状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ushort ChannelStatus()
|
|
|
|
|
{
|
|
|
|
|
PlcMgr.ResetPlc();
|
|
|
|
|
var channelStatus = PlcMgr.ChannelStatus();
|
|
|
|
|
Log.Info($"plc ChannelStatus = {channelStatus}");
|
|
|
|
|
return channelStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读plc任务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>6未连接</returns>
|
|
|
|
|
public static int ReadPlcTaskStatus()
|
|
|
|
|
{
|
|
|
|
|
return PlcMgr.ReadPlcTaskStatus();
|
|
|
|
|
}
|
|
|
|
|
}
|