评估程序代码中的报警信息
这 报警表 可视化元素可以在运行时将可视化信息写入应用程序变量。此变量可以通过编程方式进行评估。
您可以从结构中获取有关报警的信息(例如:报警组、报警 ID、状态转换的时间戳、锁存变量、消息文本) AlarmSelectionInfo
(VisuElemsAlarm
图书馆)。
为了做到这一点,在 选择 – 用于表示所选警报信息的变量 报警表的属性,指定一个类型的变量 AlarmSelectionInfo
.然后在应用程序中使用该变量,如下所示:
添加新的
PRG_VISU
頁面。添加
PRG_VISU
POU 至VISU_TASK
。打开
PRG_VISU
在编辑器中打开 POU,并插入以下程序行。宣言
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
执行
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