我目前正在为警报分析工具开发 OPC AE 客户端。不幸的是,我必须解释我的工具是如何解释问题的。可能这个列表对我的问题并不重要,但它解释了可能是根的多线程部分。
异常发生在以下代码示例的 if 子句中。
private bool areInSameGroup(ALARM_ITEM alarmItem, ALARM_ITEM groupCandidate)
{
// Check if those groups are the same one
// if the items are part of the same alarmGroup, return true.
// The if clause compares the first Item of the alarmlist of a group
// to check if the items are identically
if (findAlarmGroup(alarmItem).AlarmList[0].uniqueIdentifier ==
findAlarmGroup(groupCandidate).AlarmList[0].uniqueIdentifier)
{
return true;
}
return false;
}
下一个示例包含用于检查是否存在连接的 findAlarmGroup 方法。完整的软件运行了几秒钟,但出现了 MessageBox 并引发了 Exeption。我真的很抱歉所有的代码,但这是解释问题的唯一方法。我现在真的被困住了,因为从我的角度来看,这个消息框永远不会出现,因为在分析类开始时将每个警报分配给一个组。
如果有人愿意麻烦并查看我的代码,我会非常高兴。
// Method gets an AlarmItem and searches in every alarm group in
// the AlarmGroupList
// for the uniqueIdentifier of the received alarmItem.
private ALARM_GROUP findAlarmGroup(ALARM_ITEM alarmItem)
{
foreach (var alarmgroup in AlarmGroupList)
{
foreach (var groupedAlarm in alarmgroup.AlarmList)
{
if (groupedAlarm.uniqueIdentifier == alarmItem.uniqueIdentifier)
{
//return the found alarmgroup
return alarmgroup;
}
}
}
MessageBox.Show("FEHLER");
ALARM_GROUP noGroupFound = new ALARM_GROUP();
return noGroupFound;
}
- 外部服务器信号 (OPC AE) 引发事件(大约每 2 秒)
- 事件调用处理方法并将 OPC AE 数据附加为列表
- 处理方法:访问一个全局列表,将全局列表与新列表合并启动任务以运行带有一些全局变量的分析器和来自上面分析器的全局列表:
- 采用警报和其他几种方法,根据数据库删除一些警报并添加一个全局编号
- 一个全球性的警报计数器。之后增加数量。在主算法中搜索警报之间的相互关系,将它们分组并返回组列表。
细节:
// new list for Alarm_Group. Contains the alarm groups
AlarmGroupList = new List<ALARM_GROUP>();
// Every Alarm gets it's own Alarm Group, everytime startAnalysis
// is called
foreach (var AlarmItem in OnlineAlarmList)
{
//Create new group of alarms
ALARM_GROUP newgroup1 = new ALARM_GROUP();
//Create List of alarms in this alarmgroup
newgroup1.AlarmList = new List<ALARM_ITEM>();
//Add the alarm item to the Alarmlist of the new alarm group
newgroup1.AlarmList.Add(AlarmItem);
//Add the alarm group to the overall AlarmGroupList
AlarmGroupList.Add(newgroup1);
}
// START
// Run through all ALARM_ITEMs of the alarmevery log
foreach (var alarmItem in OnlineAlarmList)
{
int counterRunner;
// Take the Index of the currently analysed alarmItem,
// increase it by one and access the
// AlarmList with this index
counterRunner = OnlineAlarmList.IndexOf(alarmItem) + 1;
//Run through all rules of the RuleBase
foreach (var rule in rulebase.RuleBaseList)
{
// Check if selected rule can be applied on selected
// ALARM_ITEM (itemA vs. ALARM_ITEM)
if (rule.itemA == getAlarmType(alarmItem.AlarmTag))
{
//Check against any ALARM_ITEM in timeframe
bool inTimeframe = true;
ALARM_ITEM groupCandidate;
while (inTimeframe)
{
// if the current alarm items has been compared to the
// last item in the list break the loop
// and start with a new rule
int counterRunnerInternal = counterRunner;
if (counterRunnerInternal >= OnlineAlarmList.Count - 1)
break;
// group candidate is the next alarm in the list,
// hence the current alarm of the foreach loop and the
// next alarm in the list are checked
groupCandidate = OnlineAlarmList[counterRunnerInternal];
// Check if startItem and Candidate are not already
// grouped together
if (!areInSameGroup(alarmItem, groupCandidate))
//
}
}
else
{
inTimeframe = false;
}
counterRunnerInternal++;
}