1.GemManager增加Try Catch捕获异常

This commit is contained in:
HCL 2024-06-19 11:05:29 +08:00
parent d280ebedc9
commit b58d3c89f4
2 changed files with 223 additions and 194 deletions

1
.gitignore vendored
View File

@ -368,3 +368,4 @@ FodyWeavers.xsd
*.DotSettings
Output/
BuildTools/
*.json

View File

@ -506,140 +506,163 @@ namespace MECF.Framework.Common.Gem
private void Log_NewMessage(LogType loggingType, string customizedLogTypeName, DateTime timeStamp, string processName, int threadID, string source, string message)
{
// make a filter, do not show SML logging message at current window
if (message.Contains("SECS MSG Recv") || message.Contains("SECS MSG Sent"))
try
{
return;
}
// make a filter, do not show SML logging message at current window
if (message.Contains("SECS MSG Recv") || message.Contains("SECS MSG Sent"))
{
return;
}
ProgramLog += $"{timeStamp.ToString("yyyy/MM/dd HH:mm:ss,fff")} {source} 线程ID:{threadID} 内容:{message}\r\n";
ProgramLog += $"{timeStamp.ToString("yyyy/MM/dd HH:mm:ss,fff")} {source} 线程ID:{threadID} 内容:{message}\r\n";
}
catch (Exception ex)
{
LOG.Error(ex.Message, ex);
}
}
private void DataMessageReceived(string equipmentName, string connectionName, DateTime time, Kxware.Automation.Secs.DataMessage message)
{
if (connectionName == _equipment.MasterConnectionName)
try
{
string msg = $"{time.ToString("yyyy/MM/dd HH:mm:ss.fff")} 【接受】\r\n{message.ToSML()}\r\n";
Kxware.Common.Log.Info("GEM", msg);
SecsLog += msg;
if (connectionName == _equipment.MasterConnectionName)
{
string msg = $"{time.ToString("yyyy/MM/dd HH:mm:ss.fff")} 【接受】\r\n{message.ToSML()}\r\n";
Kxware.Common.Log.Info("GEM", msg);
SecsLog += msg;
//if (SecsLog.Length > 10000)
//{
// SecsLog = SecsLog.Substring(SecsLog.Length - 10000);
//}
//if (SecsLog.Length > 10000)
//{
// SecsLog = SecsLog.Substring(SecsLog.Length - 10000);
//}
}
}
catch (Exception ex)
{
LOG.Error(ex.Message, ex);
}
}
private void EventTriggered(string equipmentName, string connectionName, ulong eventID, string eventName, string eventDescription, Kxware.Common.VariableData[] associatedVariables, Kxware.Automation.Secs.DataMessage eventSecsMessage)
{
if (connectionName == _equipment.MasterConnectionName)
try
{
var associatedDataInfo = "";
if (associatedVariables.Length > 0)
if (connectionName == _equipment.MasterConnectionName)
{
associatedDataInfo = "关联数据:" + string.Join(",", associatedVariables.Select(p => p.Name + " " + p.Value.ToSML(Kxware.Common.SmlFormat.RoundBracket)));
var associatedDataInfo = "";
if (associatedVariables.Length > 0)
{
associatedDataInfo = "关联数据:" + string.Join(",", associatedVariables.Select(p => p.Name + " " + p.Value.ToSML(Kxware.Common.SmlFormat.RoundBracket)));
}
EventInfoList.Add($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} 编号:{eventID} 事件名:{eventName} {associatedDataInfo}");
}
EventInfoList.Add($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} 编号:{eventID} 事件名:{eventName} {associatedDataInfo}");
}
catch (Exception ex)
{
LOG.Error(ex.Message, ex);
}
}
private enumRemoteCommandAckCode OnReceivedRemoteCommand(string connectionName, string objSpec, string remoteCommand, List<RemoteCommandParameter> remoteCommandParameters)
{
//只接受从MasterConnection 收到的控制命令
if (connectionName != _equipment.MasterConnectionName)
return enumRemoteCommandAckCode.CannotPerformNow;
//判断控制状态在Local 状态下只接受GO-REMOTE命令
var currentCtrlState = _equipment.GetControlState();
if (currentCtrlState != GEMControlStates.Online_Remote)
try
{
if (remoteCommand.ToUpper() != "GO-REMOTE")
//只接受从MasterConnection 收到的控制命令
if (connectionName != _equipment.MasterConnectionName)
return enumRemoteCommandAckCode.CannotPerformNow;
}
var result = enumRemoteCommandAckCode.NoSuchObjectExists;
switch (remoteCommand)
{
case "GO-LOCAL":
{
if (currentCtrlState == GEMControlStates.Online_Remote)
//判断控制状态在Local 状态下只接受GO-REMOTE命令
var currentCtrlState = _equipment.GetControlState();
if (currentCtrlState != GEMControlStates.Online_Remote)
{
if (remoteCommand.ToUpper() != "GO-REMOTE")
return enumRemoteCommandAckCode.CannotPerformNow;
}
var result = enumRemoteCommandAckCode.NoSuchObjectExists;
switch (remoteCommand)
{
case "GO-LOCAL":
{
_equipment.OnlineLocal(_equipment.MasterConnectionName);
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
if (currentCtrlState == GEMControlStates.Online_Remote)
{
_equipment.OnlineLocal(_equipment.MasterConnectionName);
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
}
else
result = enumRemoteCommandAckCode.RejectedAlreadyInDesiredCondition;
}
else
result = enumRemoteCommandAckCode.RejectedAlreadyInDesiredCondition;
}
break;
break;
case "GO-REMOTE":
{
if (currentCtrlState == GEMControlStates.Online_Remote)
case "GO-REMOTE":
{
result = enumRemoteCommandAckCode.RejectedAlreadyInDesiredCondition;
if (currentCtrlState == GEMControlStates.Online_Remote)
{
result = enumRemoteCommandAckCode.RejectedAlreadyInDesiredCondition;
}
else if (!_equipment.OnlineRemote(_equipment.MasterConnectionName, out string error))
result = enumRemoteCommandAckCode.CannotPerformNow;
else
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
}
else if (!_equipment.OnlineRemote(_equipment.MasterConnectionName, out string error))
result = enumRemoteCommandAckCode.CannotPerformNow;
else
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
}
break;
break;
//PP-SELECT指令附加参数(PPID&LotID)
case "PP-SELECT":
{
try
//PP-SELECT指令附加参数(PPID&LotID)
case "PP-SELECT":
{
try
{
if (RtStatus != "AutoIdle")
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'PP-SELECT' command. Equipment State is not in AutoIdle.");
result = enumRemoteCommandAckCode.CannotPerformNow;
}
else if (remoteCommandParameters.Find(p => p.CPNAME == "PPID") == null)
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'PP-SELECT' command. PPID is not specified.");
result = enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid;
}
else if (remoteCommandParameters.Find(p => p.CPNAME == "LotID") == null)
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'PP-SELECT' command. LotID is not specified.");
result = enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid;
}
else
{
string PPID = remoteCommandParameters.Find(p => p.CPNAME == "PPID").CPVAL.GetValueAsString();
PPIDNoExtension = PPID.Replace(@"Sequence\", "").Replace(".seq", "");
LotID = remoteCommandParameters.Find(p => p.CPNAME == "LotID").CPVAL.GetValueAsString();
Kxware.Common.Log.Info("GEM", $"Received 'PP-SELECT' command. PPID={PPID}, LotID={LotID}");
//Check if rcpID is exist. if not exist, returen enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
}
}
catch (Exception)
{
result = enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid;
}
}
break;
//CREATE-JOB指令没有附加参数
case "CREATE-JOB":
{
if (RtStatus != "AutoIdle")
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'PP-SELECT' command. Equipment State is not in AutoIdle.");
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'CREATE-JOB' command. Equipment State is not in AutoIdle.");
result = enumRemoteCommandAckCode.CannotPerformNow;
}
else if (remoteCommandParameters.Find(p => p.CPNAME == "PPID") == null)
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'PP-SELECT' command. PPID is not specified.");
result = enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid;
}
else if (remoteCommandParameters.Find(p => p.CPNAME == "LotID") == null)
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'PP-SELECT' command. LotID is not specified.");
result = enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid;
}
else
{
string PPID = remoteCommandParameters.Find(p => p.CPNAME == "PPID").CPVAL.GetValueAsString();
PPIDNoExtension = PPID.Replace(@"Sequence\", "").Replace(".seq", "");
LotID = remoteCommandParameters.Find(p => p.CPNAME == "LotID").CPVAL.GetValueAsString();
Kxware.Common.Log.Info("GEM", $"Received 'PP-SELECT' command. PPID={PPID}, LotID={LotID}");
Kxware.Common.Log.Info("GEM", $"Received 'CREATE-JOB' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
//Check if rcpID is exist. if not exist, returen enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
}
}
catch (Exception)
{
result = enumRemoteCommandAckCode.AtLeastOneParameterIsInvalid;
}
}
break;
//CREATE-JOB指令没有附加参数
case "CREATE-JOB":
{
if (RtStatus != "AutoIdle")
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'CREATE-JOB' command. Equipment State is not in AutoIdle.");
result = enumRemoteCommandAckCode.CannotPerformNow;
}
else
{
Kxware.Common.Log.Info("GEM", $"Received 'CREATE-JOB' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
//具体操作
JobID = "CJ_Local_Load_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Dictionary<string, object> dictionary = new Dictionary<string, object>
//具体操作
JobID = "CJ_Local_Load_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Dictionary<string, object> dictionary = new Dictionary<string, object>
{
{ "JobId", JobID},
{ "Module", "LoadLock" },
@ -648,129 +671,134 @@ namespace MECF.Framework.Common.Gem
{ "AutoStart", true }
};
OP.DoOperation("System.CreateJob", dictionary);
OP.DoOperation("System.CreateJob", dictionary);
}
}
}
break;
break;
//START指令没有附加参数
case "START":
{
if (RtStatus != "AutoIdle" && RtStatus != "AutoRunning")
//START指令没有附加参数
case "START":
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'STRAT' command. Equipment State is not in AutoIdle or AutoRunning.");
result = enumRemoteCommandAckCode.CannotPerformNow;
if (RtStatus != "AutoIdle" && RtStatus != "AutoRunning")
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'STRAT' command. Equipment State is not in AutoIdle or AutoRunning.");
result = enumRemoteCommandAckCode.CannotPerformNow;
}
else
{
Kxware.Common.Log.Info("GEM", $"Received 'STRAT' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//具体操作
OP.DoOperation("System.StartJob", JobID);
}
}
else
break;
//ABORT指令没有附加参数
case "ABORT":
case "STOP":
{
Kxware.Common.Log.Info("GEM", $"Received 'STRAT' command.");
if (RtStatus != "AutoRunning")
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'ABORT' command. Equipment State is not in AutoRunning.");
result = enumRemoteCommandAckCode.CannotPerformNow;
}
else
{
Kxware.Common.Log.Info("GEM", $"Received 'ABORT' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//具体操作
OP.DoOperation("System.Abort");
}
}
break;
//Online指令附加参数(ModuleID)
case "Online":
{
Kxware.Common.Log.Info("GEM", $"Received 'Online' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//具体操作
OP.DoOperation("System.StartJob", JobID);
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation($"{module}.SetOnline");
}
}
break;
break;
//ABORT指令没有附加参数
case "ABORT":
case "STOP":
{
if (RtStatus != "AutoRunning")
//Offline指令附加参数(ModuleID)
case "Offline":
{
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'ABORT' command. Equipment State is not in AutoRunning.");
result = enumRemoteCommandAckCode.CannotPerformNow;
}
else
{
Kxware.Common.Log.Info("GEM", $"Received 'ABORT' command.");
Kxware.Common.Log.Info("GEM", $"Received 'Offline' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//具体操作
OP.DoOperation("System.Abort");
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation($"{module}.SetOffline");
}
}
break;
break;
//Online指令附加参数(ModuleID)
case "Online":
{
Kxware.Common.Log.Info("GEM", $"Received 'Online' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//CreateWafer指令附加参数(ModuleID,SlotID)
case "CreateWafer":
{
Kxware.Common.Log.Info("GEM", $"Received 'CreateWafer' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation($"{module}.SetOnline");
}
break;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"CreateWafer", module, slot);
}
break;
//Offline指令附加参数(ModuleID)
case "Offline":
{
Kxware.Common.Log.Info("GEM", $"Received 'Offline' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//CreateTray指令附加参数(ModuleID,SlotID)
case "CreateTray":
{
Kxware.Common.Log.Info("GEM", $"Received 'CreateTray' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation($"{module}.SetOffline");
}
break;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"CreateTray", module, slot);
}
break;
//CreateWafer指令附加参数(ModuleID,SlotID)
case "CreateWafer":
{
Kxware.Common.Log.Info("GEM", $"Received 'CreateWafer' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//DeleteWafer指令附加参数(ModuleID,SlotID)
case "DeleteWafer":
{
Kxware.Common.Log.Info("GEM", $"Received 'DeleteWafer' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"CreateWafer", module, slot);
}
break;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"DeleteWafer", module, slot);
}
break;
//CreateTray指令附加参数(ModuleID,SlotID)
case "CreateTray":
{
Kxware.Common.Log.Info("GEM", $"Received 'CreateTray' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//DeleteTray指令附加参数(ModuleID)
case "DeleteTray":
{
Kxware.Common.Log.Info("GEM", $"Received 'DeleteTray' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"CreateTray",module,slot);
}
break;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"DeleteTray", module, slot);
}
break;
//DeleteWafer指令附加参数(ModuleID,SlotID)
case "DeleteWafer":
{
Kxware.Common.Log.Info("GEM", $"Received 'DeleteWafer' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
default:
{
Kxware.Common.Log.Error("GEM", $"Un-handled remote command: {remoteCommand}");
}
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"DeleteWafer", module, slot);
}
break;
break;
}
//DeleteTray指令附加参数(ModuleID)
case "DeleteTray":
{
Kxware.Common.Log.Info("GEM", $"Received 'DeleteTray' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"DeleteTray", module, slot);
}
break;
default:
{
Kxware.Common.Log.Error("GEM", $"Un-handled remote command: {remoteCommand}");
}
break;
return result;
}
catch (Exception)
{
return enumRemoteCommandAckCode.CannotPerformNow;
}
return result;
}
private bool SetSoftwareVersion(string softwareVersion)