Skip to main content

Evaluating Alarm Information in the Program Code

The Alarm Table visualization element can write information from the visualization to an application variable at runtime. This variable can be evaluated programmatically.

You get information about an alarm (for example: alarm group, alarm ID, timestamp of status transitions, latch variables, message texts) from the structure AlarmSelectionInfo (VisuElemsAlarm library).

To do this, in the SelectionVariable for information about selected alarm property of the alarm table, specify a variable of type AlarmSelectionInfo. Then use the variable in the application as follows:

  1. Add a new PRG_VISU POU.

  2. Add the PRG_VISU POU to VISU_TASK.

  3. Open the PRG_VISU POU in the editor and insert the following program lines.

    Declaration

    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                        

    Implementation

    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