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.

82 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Entity.Constant;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Execute;
using Service.Execute.Api;
using Service.Execute.StaticTools;
using Service.Plc.Client;
namespace Service.Mgr;
[Scope("SingleInstance")]
public class PlcTaskMgr
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcTaskMgr));
/// <summary>
///
/// </summary>
/// <param name="taskNo">消防移仓传入5自动移仓传入2</param>
/// <param name="ingStatus"></param>
/// <param name="exceptionStatus"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public bool QueryPlcTask(int taskNo, int ingStatus, int exceptionStatus)
{
Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute start -------------------");
bool isSuccess = false;
InvokeStatus invokeStatus = Invoker.Invoke("QueryPlcTask", 1000, 5,
() => isSuccess, () =>
{
int readPlcTaskStatus = 0;
if (taskNo == 5)
{
readPlcTaskStatus = PlcMgr.ReadFireStatus();
}
else if (taskNo == 2)
{
readPlcTaskStatus = PlcMgr.ReadMoveStatus();
}
Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute resp readPlcTaskStatus={readPlcTaskStatus}");
if (ingStatus == readPlcTaskStatus)
{
}
else if (exceptionStatus == readPlcTaskStatus)
{
Log.Info(
$"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute fail readPlcTaskStatus={readPlcTaskStatus}");
throw new Exception("PlcTaskMgr.QueryPlcTask readPlcTaskStatus=" + readPlcTaskStatus);
}
else if (9000 == readPlcTaskStatus || 1001== readPlcTaskStatus )
{
Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute success readPlcTaskStatus={readPlcTaskStatus}");
isSuccess = true;
}
}, () =>
{
Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute ing");
if (taskNo == 2)
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoBatteryMove);
}else if (taskNo == 5)
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoFireRemove);
}
}, true, () => { }
, 5, InvokeStatus.Exception);
if (InvokeStatus.Exception == invokeStatus)
{
return false;
}
Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute end success-------------------");
return true;
}
}