|
|
|
using Entity.Constant;
|
|
|
|
using log4net;
|
|
|
|
using Service.Charger.Client;
|
|
|
|
using Service.Mgr;
|
|
|
|
using Service.Padar.Client;
|
|
|
|
using Service.PlcAfrica.Client;
|
|
|
|
using Service.PlcAfrica.Msg;
|
|
|
|
|
|
|
|
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 ushort ReadAction()
|
|
|
|
{
|
|
|
|
return PlcAfricaMgr.AutoActionStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static bool RobotWorkFinish()
|
|
|
|
{
|
|
|
|
return PlcAfricaMgr.RobotWorkFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool RobotReady()
|
|
|
|
{
|
|
|
|
return PlcAfricaMgr.RobotReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 是否远程模式
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool IsRemote()
|
|
|
|
{
|
|
|
|
return PlcAfricaMgr.IsAutoAndRemote();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*/// <summary>
|
|
|
|
/// 是否初始化完成
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool IsInit()
|
|
|
|
{
|
|
|
|
return ClientMgr.PlcClient!.Init;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 是否自动
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool IsAuto()
|
|
|
|
{
|
|
|
|
return PlcAfricaMgr.IsAutoAndRemote();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 下发启动换电
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool StartSwapping(string inBinNo, string outBinNo)
|
|
|
|
{
|
|
|
|
|
|
|
|
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Plc,SwapConstant.PlcProtocol.StartSwap,
|
|
|
|
|
|
|
|
$"出仓位:{outBinNo},入仓位:{inBinNo}" ,(int)SwapConstant.CommunicationType.Send);
|
|
|
|
|
|
|
|
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
|
|
|
|
if (PlcAfricaMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo)))
|
|
|
|
{
|
|
|
|
Log.Info($"PlcApi StartSwapping done");
|
|
|
|
return PlcAfricaMgr.StartSwap();
|
|
|
|
}
|
|
|
|
return PlcAfricaMgr.StationCommandFeedback();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 电池搬运
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool StartBatteryMove(string inBinNo, string outBinNo)
|
|
|
|
{
|
|
|
|
|
|
|
|
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Plc,SwapConstant.PlcProtocol.StartBatteryMove,
|
|
|
|
|
|
|
|
$"出仓位:{inBinNo},入仓位:{outBinNo}" ,(int)SwapConstant.CommunicationType.Send);
|
|
|
|
|
|
|
|
Log.Info($"PlcApi StartBatteryMove param= inBinNo={inBinNo}, outBinNo={outBinNo}");
|
|
|
|
ClientMgr.PlcClient?.SendMoveCommandReq(Convert.ToByte(inBinNo), Convert.ToByte(outBinNo));
|
|
|
|
|
|
|
|
|
|
|
|
Log.Info($"PlcApi StartBatteryMove done");
|
|
|
|
return ClientMgr.PlcClient.SwapStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*/// <summary>
|
|
|
|
/// 发送初始化命令
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool Init()
|
|
|
|
{
|
|
|
|
Log.Info($"PlcApi Init ");
|
|
|
|
ClientMgr.PlcClient?.SendInitializeCommandReq();
|
|
|
|
Log.Info($"PlcApi Init done");
|
|
|
|
return true;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 发送红绿灯
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool Traffic(ushort light)
|
|
|
|
{
|
|
|
|
return PlcAfricaMgr.LightControl(light);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 发送红绿灯
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool CarStatus(ushort cmd)
|
|
|
|
{
|
|
|
|
return PlcAfricaMgr.CarStatus(cmd);
|
|
|
|
}
|
|
|
|
}
|