Valutazione delle informazioni di allarme nel codice del programma
IL Tabella degli allarmi l'elemento di visualizzazione può scrivere informazioni dalla visualizzazione a una variabile dell'applicazione in fase di esecuzione. Questa variabile può essere valutata a livello di programmazione.
Si ottengono informazioni su un allarme (ad esempio: gruppo di allarme, ID di allarme, timestamp delle transizioni di stato, variabili di latch, testi dei messaggi) dalla struttura AlarmSelectionInfo
(VisuElemsAlarm
biblioteca).
Per fare questo, nel Selezione – Variabile per informazioni sull'allarme selezionato proprietà della tabella degli allarmi, specificare una variabile di tipo AlarmSelectionInfo
Quindi utilizzare la variabile nell'applicazione come segue:
Aggiungi un nuovo
PRG_VISU
POU.Aggiungere il
PRG_VISU
POU aVISU_TASK
.Aprire il
PRG_VISU
POU nell'editor e inserisci le seguenti righe di programma.Dichiarazione
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
Implementazione
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