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 *.DotSettings
Output/ Output/
BuildTools/ 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) 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 try
if (message.Contains("SECS MSG Recv") || message.Contains("SECS MSG Sent"))
{ {
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) 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"; if (connectionName == _equipment.MasterConnectionName)
Kxware.Common.Log.Info("GEM", msg); {
SecsLog += msg; 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) //if (SecsLog.Length > 10000)
//{ //{
// SecsLog = SecsLog.Substring(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) 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 (connectionName == _equipment.MasterConnectionName)
if (associatedVariables.Length > 0)
{ {
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) private enumRemoteCommandAckCode OnReceivedRemoteCommand(string connectionName, string objSpec, string remoteCommand, List<RemoteCommandParameter> remoteCommandParameters)
{ {
//只接受从MasterConnection 收到的控制命令 try
if (connectionName != _equipment.MasterConnectionName)
return enumRemoteCommandAckCode.CannotPerformNow;
//判断控制状态在Local 状态下只接受GO-REMOTE命令
var currentCtrlState = _equipment.GetControlState();
if (currentCtrlState != GEMControlStates.Online_Remote)
{ {
if (remoteCommand.ToUpper() != "GO-REMOTE") //只接受从MasterConnection 收到的控制命令
if (connectionName != _equipment.MasterConnectionName)
return enumRemoteCommandAckCode.CannotPerformNow; return enumRemoteCommandAckCode.CannotPerformNow;
}
var result = enumRemoteCommandAckCode.NoSuchObjectExists; //判断控制状态在Local 状态下只接受GO-REMOTE命令
switch (remoteCommand) var currentCtrlState = _equipment.GetControlState();
{ if (currentCtrlState != GEMControlStates.Online_Remote)
case "GO-LOCAL": {
{ if (remoteCommand.ToUpper() != "GO-REMOTE")
if (currentCtrlState == GEMControlStates.Online_Remote) return enumRemoteCommandAckCode.CannotPerformNow;
}
var result = enumRemoteCommandAckCode.NoSuchObjectExists;
switch (remoteCommand)
{
case "GO-LOCAL":
{ {
_equipment.OnlineLocal(_equipment.MasterConnectionName); if (currentCtrlState == GEMControlStates.Online_Remote)
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed; {
_equipment.OnlineLocal(_equipment.MasterConnectionName);
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
}
else
result = enumRemoteCommandAckCode.RejectedAlreadyInDesiredCondition;
} }
else break;
result = enumRemoteCommandAckCode.RejectedAlreadyInDesiredCondition;
}
break;
case "GO-REMOTE": case "GO-REMOTE":
{
if (currentCtrlState == GEMControlStates.Online_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)) break;
result = enumRemoteCommandAckCode.CannotPerformNow;
else
result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
}
break;
//PP-SELECT指令附加参数(PPID&LotID) //PP-SELECT指令附加参数(PPID&LotID)
case "PP-SELECT": case "PP-SELECT":
{ {
try 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") 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; 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 else
{ {
string PPID = remoteCommandParameters.Find(p => p.CPNAME == "PPID").CPVAL.GetValueAsString(); Kxware.Common.Log.Info("GEM", $"Received 'CREATE-JOB' command.");
PPIDNoExtension = PPID.Replace(@"Sequence\", "").Replace(".seq", ""); result = enumRemoteCommandAckCode.AcknowledgeCommandPerformed;
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 //具体操作
JobID = "CJ_Local_Load_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed; Dictionary<string, object> dictionary = new Dictionary<string, object>
}
}
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", JobID}, { "JobId", JobID},
{ "Module", "LoadLock" }, { "Module", "LoadLock" },
@ -648,129 +671,134 @@ namespace MECF.Framework.Common.Gem
{ "AutoStart", true } { "AutoStart", true }
}; };
OP.DoOperation("System.CreateJob", dictionary); OP.DoOperation("System.CreateJob", dictionary);
}
} }
} break;
break;
//START指令没有附加参数 //START指令没有附加参数
case "START": case "START":
{
if (RtStatus != "AutoIdle" && RtStatus != "AutoRunning")
{ {
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'STRAT' command. Equipment State is not in AutoIdle or AutoRunning."); if (RtStatus != "AutoIdle" && RtStatus != "AutoRunning")
result = enumRemoteCommandAckCode.CannotPerformNow; {
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; result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//具体操作 string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation("System.StartJob", JobID); OP.DoOperation($"{module}.SetOnline");
} }
} break;
break;
//ABORT指令没有附加参数 //Offline指令附加参数(ModuleID)
case "ABORT": case "Offline":
case "STOP":
{
if (RtStatus != "AutoRunning")
{ {
Kxware.Common.Log.Warn("GEM", $"Cannot perform 'ABORT' command. Equipment State is not in AutoRunning."); Kxware.Common.Log.Info("GEM", $"Received 'Offline' command.");
result = enumRemoteCommandAckCode.CannotPerformNow;
}
else
{
Kxware.Common.Log.Info("GEM", $"Received 'ABORT' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed; result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
//具体操作 string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation("System.Abort"); OP.DoOperation($"{module}.SetOffline");
} }
} break;
break;
//Online指令附加参数(ModuleID) //CreateWafer指令附加参数(ModuleID,SlotID)
case "Online": case "CreateWafer":
{ {
Kxware.Common.Log.Info("GEM", $"Received 'Online' command."); Kxware.Common.Log.Info("GEM", $"Received 'CreateWafer' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed; result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString(); string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation($"{module}.SetOnline"); int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
} OP.DoOperation($"CreateWafer", module, slot);
break; }
break;
//Offline指令附加参数(ModuleID) //CreateTray指令附加参数(ModuleID,SlotID)
case "Offline": case "CreateTray":
{ {
Kxware.Common.Log.Info("GEM", $"Received 'Offline' command."); Kxware.Common.Log.Info("GEM", $"Received 'CreateTray' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed; result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString(); string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
OP.DoOperation($"{module}.SetOffline"); int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
} OP.DoOperation($"CreateTray", module, slot);
break; }
break;
//CreateWafer指令附加参数(ModuleID,SlotID) //DeleteWafer指令附加参数(ModuleID,SlotID)
case "CreateWafer": case "DeleteWafer":
{ {
Kxware.Common.Log.Info("GEM", $"Received 'CreateWafer' command."); Kxware.Common.Log.Info("GEM", $"Received 'DeleteWafer' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed; result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString(); string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0); int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"CreateWafer", module, slot); OP.DoOperation($"DeleteWafer", module, slot);
} }
break; break;
//CreateTray指令附加参数(ModuleID,SlotID) //DeleteTray指令附加参数(ModuleID)
case "CreateTray": case "DeleteTray":
{ {
Kxware.Common.Log.Info("GEM", $"Received 'CreateTray' command."); Kxware.Common.Log.Info("GEM", $"Received 'DeleteTray' command.");
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed; result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString(); string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString();
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0); int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0);
OP.DoOperation($"CreateTray",module,slot); OP.DoOperation($"DeleteTray", module, slot);
} }
break; break;
//DeleteWafer指令附加参数(ModuleID,SlotID) default:
case "DeleteWafer": {
{ Kxware.Common.Log.Error("GEM", $"Un-handled remote command: {remoteCommand}");
Kxware.Common.Log.Info("GEM", $"Received 'DeleteWafer' command."); }
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed;
string module = remoteCommandParameters.Find(p => p.CPNAME == "ModuleID").CPVAL.GetValueAsString(); break;
int slot = remoteCommandParameters.Find(p => p.CPNAME == "SlotID").CPVAL.GetValueAsInt(0); }
OP.DoOperation($"DeleteWafer", module, slot);
}
break;
//DeleteTray指令附加参数(ModuleID) return result;
case "DeleteTray": }
{ catch (Exception)
Kxware.Common.Log.Info("GEM", $"Received 'DeleteTray' command."); {
result = enumRemoteCommandAckCode.AcknowledgeCommandWillBePerformed; return enumRemoteCommandAckCode.CannotPerformNow;
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;
} }
private bool SetSoftwareVersion(string softwareVersion) private bool SetSoftwareVersion(string softwareVersion)