dc/Handlers/EventHandlers/Process_FinishHandler.cs

215 lines
9.0 KiB
C#
Raw Permalink Normal View History

2022-04-01 17:03:54 +08:00
#region << >>
/*----------------------------------------------------------------
* Hupe
* 2021/10/14 20:04:50
* V1.0.0
*
*
* ----------------------------------------------------------------
*
*
*
*
* V1.0.1
*----------------------------------------------------------------*/
#endregion << >>
using ARI.EAP.HOST.Common;
using ARI.EAP.HOST.MQ;
using ARI.EAP.HOST.MQ.body;
using ARI.EAP.HOST.SRD;
using Glorysoft.SECS.EQP.Common;
using Glorysoft.SECS.EQP.Utilities;
using Glorysoft.SECSwell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ARI.EAP.HOST.Handlers.EventHandlers
{
public class Process_FinishHandler : IEventHandler
{
public void Execute(SECSTransaction trans, EVENT even)
{
try
{
MQMessage mQMessage = new MQMessage();
mQMessage.header.messageName = "ProcessFinished";
ProcessFinishBody processFinishBody = new ProcessFinishBody();
processFinishBody.spoolingFlag = EquipmentStatus.SpoolingFlag.ToString();
int index = 1;
foreach (var key in even.validVariables)
{
2022-12-16 13:01:24 +08:00
string name = Configurations.conf.sRDConfiguration.tryGetSVOrDV(key);
2022-04-01 17:03:54 +08:00
switch (name)
{
case ("SubstrateID"):
{
2023-02-23 11:33:23 +08:00
processFinishBody.substrateId = trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Value.ToString();
2022-04-01 17:03:54 +08:00
}
break;
case ("Clock"):
{
2023-02-23 11:33:23 +08:00
processFinishBody.eventTimestamp = trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Value.ToString();
2022-04-01 17:03:54 +08:00
}
break;
case ("StateFlag"):
{
2023-02-23 11:33:23 +08:00
processFinishBody.stateFlag = trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Value.ToString();
trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Name = name;
2022-04-01 17:03:54 +08:00
}
break;
2023-02-23 11:33:23 +08:00
case ("ProcessResult"):
2022-04-01 17:03:54 +08:00
{
2023-02-23 11:33:23 +08:00
processFinishBody.materialStatus = trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Value.ToString();
2022-04-01 17:03:54 +08:00
}
break;
case ("CurrentEquipmentState"):
{
2023-02-23 11:33:23 +08:00
processFinishBody.currentEquipmentState = trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Value.ToString();
2022-04-01 17:03:54 +08:00
}
break;
case ("PreviousEquipmentState"):
{
2023-02-23 11:33:23 +08:00
processFinishBody.previousEquipmentState = trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Value.ToString();
2022-04-01 17:03:54 +08:00
}
break;
default:
{
2023-02-23 11:33:23 +08:00
formatCheck(key, trans.Primary.Root.Item(3).Item(1).Item(2).Item(index));
processFinishBody.processData.Add($"{name}", trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Value.ToString());
2022-04-01 17:03:54 +08:00
}
break;
}
2023-02-23 11:33:23 +08:00
trans.Primary.Root.Item(3).Item(1).Item(2).Item(index).Name = name;
2022-04-01 17:03:54 +08:00
index++;
}
2022-12-16 13:01:24 +08:00
Global.MF.addlog(trans, LoggerService.Receive, even.name, 0);
2022-04-01 17:03:54 +08:00
LoggerService.SECSLogger.Info(trans.Primary);
2022-12-16 13:01:24 +08:00
Global.MF.addlog(trans, LoggerService.Send, even.name, 1);
2022-04-01 17:03:54 +08:00
LoggerService.SECSLogger.Info(trans.Secondary);
mQMessage.body = processFinishBody;
Task.Run(() =>
{
MainForm.mq.EAPRequest(mQMessage);
MainForm.mq.EAPRequestToRTDB(mQMessage);
});
}
catch (Exception e)
{
LoggerService.SECSLogger.Error(e);
}
}
public void formatCheck(uint id,SECSItem item)
{
2022-12-16 13:01:24 +08:00
eSECS_FORMAT standardFormat = Configurations.conf.sRDConfiguration.GetSECS_FORMAT(id);
2022-04-01 17:03:54 +08:00
eSECS_FORMAT format = item.Format;
if (standardFormat != format)
{
MQMessage mQMessage = new MQMessage();
mQMessage.header.messageName = "FormatError";
FormatErrorBody formatErrorBody = new FormatErrorBody();
formatErrorBody.eventName = "ProcessFinished";
2022-12-16 13:01:24 +08:00
formatErrorBody.paramName = Configurations.conf.sRDConfiguration.tryGetSVOrDV(id);
2022-04-01 17:03:54 +08:00
formatErrorBody.paramValue = item.Value.ToString();
switch (format)
{
case eSECS_FORMAT.LIST:
formatErrorBody.paramFormat = "L";
break;
case eSECS_FORMAT.BOOLEAN:
formatErrorBody.paramFormat = "B";
break;
case eSECS_FORMAT.ASCII:
formatErrorBody.paramFormat = "A";
break;
case eSECS_FORMAT.I8:
formatErrorBody.paramFormat = "I8";
break;
case eSECS_FORMAT.I2:
formatErrorBody.paramFormat = "I2";
break;
case eSECS_FORMAT.I1:
formatErrorBody.paramFormat = "I1";
break;
case eSECS_FORMAT.I4:
formatErrorBody.paramFormat = "I4";
break;
case eSECS_FORMAT.U1:
formatErrorBody.paramFormat = "U1";
break;
case eSECS_FORMAT.U2:
formatErrorBody.paramFormat = "U2";
break;
case eSECS_FORMAT.U4:
formatErrorBody.paramFormat = "U4";
break;
case eSECS_FORMAT.U8:
formatErrorBody.paramFormat = "U8";
break;
case eSECS_FORMAT.F8:
formatErrorBody.paramFormat = "F8";
break;
case eSECS_FORMAT.F4:
formatErrorBody.paramFormat = "F4";
break;
default:
formatErrorBody.paramFormat = "A";
break;
}
switch(standardFormat)
{
case eSECS_FORMAT.LIST:
formatErrorBody.standardFormat = "L";
break;
case eSECS_FORMAT.BOOLEAN:
formatErrorBody.standardFormat = "B";
break;
case eSECS_FORMAT.ASCII:
formatErrorBody.standardFormat = "A";
break;
case eSECS_FORMAT.I8:
formatErrorBody.standardFormat = "I8";
break;
case eSECS_FORMAT.I2:
formatErrorBody.standardFormat = "I2";
break;
case eSECS_FORMAT.I1:
formatErrorBody.standardFormat = "I1";
break;
case eSECS_FORMAT.I4:
formatErrorBody.standardFormat = "I4";
break;
case eSECS_FORMAT.U1:
formatErrorBody.standardFormat = "U1";
break;
case eSECS_FORMAT.U2:
formatErrorBody.standardFormat = "U2";
break;
case eSECS_FORMAT.U4:
formatErrorBody.standardFormat = "U4";
break;
case eSECS_FORMAT.U8:
formatErrorBody.standardFormat = "U8";
break;
case eSECS_FORMAT.F8:
formatErrorBody.standardFormat = "F8";
break;
case eSECS_FORMAT.F4:
formatErrorBody.standardFormat = "F4";
break;
default:
formatErrorBody.standardFormat = "A";
break;
}
mQMessage.body = formatErrorBody;
Task.Run(() => MainForm.mq.EAPRequest(mQMessage));
}
}
}
}