2

私は現在、アラーム アナライザー ツール用の 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 秒ごと)
  • イベントは HandlingMethod を呼び出し、OPC AE データをリストとして添付します
  • HandlingMethod: グローバル リストにアクセスし、グローバル リストを新しいものとマージします。いくつかのグローバル変数と上記のアナライザーからのグローバル リストを使用してアナライザーを実行するタスクを開始します。
  • アラームと他のいくつかのメソッドを取得し、データベースに基づいていくつかのアラームを削除し、グローバル番号を追加します
  • アラームに対するグローバル カウンター。その後数を増やします。メイン アルゴリズムでは、アラーム間の相互関係を検索し、それらをグループ化し、グループのリストを返します。

詳細:

// 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++;
     }
4

0 に答える 0