Files
2026-07-16 16:47:53 +08:00

159 lines
5.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Threading;
using MesServerWork;
using MisDataSaveDate;
namespace MesServerFunctions
{
partial class FunctionMES
{
private const string LGAgvWorkStation = "AC1101";
private class LGAgvDispatchContext
{
public DeviceDriver_BasicData.CustomeEvetnArgs EventArgs { get; set; }
public string RouteCode { get; set; }
public string ActionCode { get; set; }
public string ProcessPointType { get; set; }
public string Description { get; set; }
}
private class LGAgvProductInfo
{
public int EngineTypeID { get; set; }
public string EngineType { get; set; }
public string EngineID { get; set; }
public string OrderForm { get; set; }
public int PartPalletCode { get; set; }
}
private void fun_LGAgvDispatch(DeviceDriver_BasicData.CustomeEvetnArgs e, string routeCode, string actionCode, string processPointType, string description)
{
ThreadPool.QueueUserWorkItem(LGAgvDispatch, new LGAgvDispatchContext
{
EventArgs = e,
RouteCode = routeCode,
ActionCode = actionCode,
ProcessPointType = processPointType,
Description = description
});
}
private void LGAgvDispatch(object state)
{
string opName = LGAgvWorkStation;
try
{
LGAgvDispatchContext context = (LGAgvDispatchContext)state;
if (context == null || context.EventArgs == null)
{
throw new Exception("AGV调度参数为空");
}
string eventOpName = Convert.ToString(context.EventArgs.OpName);
opName = string.IsNullOrWhiteSpace(eventOpName) ? LGAgvWorkStation : eventOpName;
LGAgvProductInfo productInfo = ReadLGAgvProductInfo(opName);
LGWEB_DispatchResult result = LGWEB_BusinessLogic.DispatchAGV(new LGWEB_DispatchRequest
{
routeCode = context.RouteCode,
productModelCode = productInfo.EngineTypeID.ToString(),
productModel = productInfo.EngineType,
actionCode = context.ActionCode,
processPointType = context.ProcessPointType,
workStation = LGAgvWorkStation,
productCode = productInfo.EngineID,
containerNo = productInfo.PartPalletCode > 0 ? productInfo.PartPalletCode.ToString() : "",
orderNo = productInfo.OrderForm,
operatorCode = "PLC",
operatorName = "PLC自动",
remark = context.Description
}, "PLC_AUTO", true);
if (!result.Success)
{
throw new Exception(result.Message);
}
string logText = $"临工AGV任务已下发动作={context.ActionCode},起点={result.StartPosition},终点={result.EndPosition}任务ID={result.RequestTaskId}";
MisDataSaveDate.Helper.ApiLogHelper.SaveMesLog(opName, logText, MisDataSaveDate.Helper.MesLogType.INFO);
SendMessage.AsyncSendMessage_Notice(opName, logText);
}
catch (Exception ex)
{
string logText = $"临工AGV调度失败{ex.Message}";
MisDataSaveDate.Helper.ApiLogHelper.SaveMesLog(opName, logText, MisDataSaveDate.Helper.MesLogType.ERROR);
SendMessage.AsyncSendMessage_Notice(opName, logText);
MyLog4Net.MyLogHelper.Error("Function1053_LGAgvDispatch", $"{logText}{Environment.NewLine}{ex}");
}
}
private LGAgvProductInfo ReadLGAgvProductInfo(string opName)
{
LGAgvProductInfo productInfo = ReadLGAgvProductInfoFromMes(opName);
if (productInfo.EngineTypeID <= 0 || string.IsNullOrWhiteSpace(productInfo.EngineType))
{
productInfo = ReadLGAgvProductInfoFromPlc(opName);
}
if (productInfo.EngineTypeID <= 0 || string.IsNullOrWhiteSpace(productInfo.EngineType))
{
throw new Exception("未读取到产品型号无法解析AGV产品点位配置");
}
return productInfo;
}
private LGAgvProductInfo ReadLGAgvProductInfoFromMes(string opName)
{
int engineTypeID = 0;
string engineType = "";
string engineID = "";
string orderForm = "";
try
{
MIS_BASE.GetEngineTypeFromPLC_MES(opName, out engineTypeID, out engineType, out engineID, out orderForm);
}
catch
{
}
return new LGAgvProductInfo
{
EngineTypeID = engineTypeID,
EngineType = engineType ?? "",
EngineID = engineID ?? "",
OrderForm = orderForm ?? "",
PartPalletCode = 0
};
}
private LGAgvProductInfo ReadLGAgvProductInfoFromPlc(string opName)
{
int engineTypeID = 0;
int partPalletCode = 0;
string engineType = "";
string engineID = "";
string orderForm = "";
try
{
MIS_BASE.GetEngineTypeFromPLC(opName, out engineTypeID, out engineType, out engineID, out partPalletCode, out orderForm);
}
catch
{
}
return new LGAgvProductInfo
{
EngineTypeID = engineTypeID,
EngineType = engineType ?? "",
EngineID = engineID ?? "",
OrderForm = orderForm ?? "",
PartPalletCode = partPalletCode
};
}
}
}