Skip to main content

Évaluation des informations d'alarme dans le code du programme

Le Tableau d'alarme L'élément de visualisation peut écrire des informations de la visualisation dans une variable d'application au moment de l'exécution. Cette variable peut être évaluée par programmation.

Vous obtenez des informations sur une alarme (par exemple : groupe d'alarmes, ID d'alarme, horodatage des transitions d'état, variables de verrouillage, textes de message) à partir de la structure AlarmSelectionInfo (VisuElemsAlarm bibliothèque).

Pour ce faire, dans le SélectionVariable pour les informations sur l'alarme sélectionnée propriété de la table d'alarme, spécifiez une variable de type AlarmSelectionInfo. Utilisez ensuite la variable dans l'application comme suit :

  1. Ajouter un nouveau PRG_VISU Pou.

  2. Ajoutez le PRG_VISU POU à VISU_TASK.

  3. Ouvrir le PRG_VISU POU dans l'éditeur et insérez les lignes de programme suivantes.

    Déclaration

    PROGRAM PRG_VISU
    VAR
        alarmSelectionInfoDefault : AlarmSelectionInfoDefault;
        sLastTimestampDate : STRING;
        sLastTimestampTime : STRING;
        sLatch1 : STRING;
        sLatch2 : STRING;
        wsMessage1 : WSTRING := "No selection";
        wsMessage2 : WSTRING := "No selection";
        pInt : POINTER TO INT;
        xInit: BOOL := TRUE;
        pString : POINTER TO STRING;
        cbsFormattedValueLatch1 : CharBufferString(uiBufferSize := 0, stringType := TYPE_CLASS.TYPE_STRING);
        cbsFormattedValueLatch2 : CharBufferString(uiBufferSize := 0, stringType := TYPE_CLASS.TYPE_STRING);
        abyLocalBufferLatch1 : ARRAY[0..LENGTH] OF BYTE;
        abyLocalBufferLatch2 : ARRAY[0..LENGTH] OF BYTE;
        iPrevSelectionChangedCounter: INT;
        END_VAR
    VAR CONSTANT
        // The length of the string of the local CharBufferString instance
        LENGTH : INT := 80 * 2;
    END_VAR                        

    Mise en œuvre

    IF xInit THEN
        cbsFormattedValueLatch1.Init(pBuffer:=ADR(abyLocalBufferLatch1), uiBufferSize:=INT_TO_UINT(LENGTH + 1), stringType:=TYPE_CLASS.TYPE_STRING);
        cbsFormattedValueLatch2.Init(pBuffer:=ADR(abyLocalBufferLatch2), uiBufferSize:=INT_TO_UINT(LENGTH + 1), stringType:=TYPE_CLASS.TYPE_STRING);
        xInit := FALSE;
    END_IF
    IF alarmSelectionInfoDefault.AlarmSelectionInfo.iSelectionChangedCounter <> iPrevSelectionChangedCounter THEN
        // Format Date/Time as string
        sLastTimestampDate := AlarmManager.FormatDate(alarmSelectionInfoDefault.AlarmSelectionInfo.timeStampLast, AlarmManager.AlarmGlobals.g_sDateFormat);
        sLastTimestampTime := AlarmManager.FormatTime(alarmSelectionInfoDefault.AlarmSelectionInfo.timeStampLast, AlarmManager.AlarmGlobals.g_sTimeFormat);
        // Retrieve latch variables as string
        cbsFormattedValueLatch1.FromString('');
        pString := FormatTypedValue(alarmSelectionInfoDefault.AlarmSelectionInfo.paLatchVariables^[0], cbsFormattedValueLatch1);
        STU.StrCpyA(ADR(sLatch1), SIZEOF(sLatch1), pString);
        cbsFormattedValueLatch2.FromString('');
        pString := FormatTypedValue(alarmSelectionInfoDefault.AlarmSelectionInfo.paLatchVariables^[1], cbsFormattedValueLatch2);
        STU.StrCpyA(ADR(sLatch2), SIZEOF(sLatch2), pString);
        // Retrieve messages
        STU.StrCpyW(ADR(wsMessage1), SIZEOF(wsMessage1), alarmSelectionInfoDefault.AlarmSelectionInfo.papwsAlarmMessages^[0]);
        STU.StrCpyW(ADR(wsMessage2), SIZEOF(wsMessage2), alarmSelectionInfoDefault.AlarmSelectionInfo.papwsAlarmMessages^[1]);
        iPrevSelectionChangedCounter := alarmSelectionInfoDefault.AlarmSelectionInfo.iSelectionChangedCounter;
    END_IF