Alarm Manager problem

Hello Community,

I’ve been struggling with a problem for the past two days and could really use some help. Here’s what I’m trying to achieve:

I want to read a message from the Alarm table in WebVisu (for example, “Modbus communication error”) and store it in a string variable. My goal is to modify this message and display it again for another error in the alarm table. I discovered that this can be done using the AlarmManager 4.6.0.0 library (internal).

I wrote the following code lines in ST:

//declaration
arritfAlarmsFromAll : ARRAY [0 … 20] OF IAlarm2;

sMessage:STRING;
parritfAlarms:POINTER TO ARRAY[0…15] OF IAlarm;
itfAlarmGroup : IAlarmGroup;
//code
parritfAlarms:= ADR(arritfAlarmsFromAll);
IF parritfAlarms <> 0 THEN
psMessage := parritfAlarms[1].GetMessage(stringType := __SYSTEM.TYPE_CLASS.TYPE_STRING);
sMessage := psMessage^;
END_IF

However, I’m encountering an exception error (access violation) on the PLC. When I click on the error, it takes me to the line where the pointer is used ( psMessage := parritfAlarms[2].GetMessage(stringType := __SYSTEM.TYPE_CLASS.TYPE_STRING);).
I’m not sure what is going wrong.

Any help would be greatly appreciated. Thanks!

2025-03-12_11h25_22



  1. SelectedRow+1 ↩︎

  2. SelectedRow+1 ↩︎

Hello,

It looks like the issue might be due to an incorrect way of accessing the alarm message from parritfAlarms. Here are a few potential problems and solutions:

1. Incorrect Use of Pointer

  • You’re treating parritfAlarms as if it directly contains alarm instances, but it’s a pointer to an array.
  • The function GetMessage() needs to be called on a specific alarm instance, not on the pointer itself.

2. Fixing the Pointer Dereferencing

Instead of calling GetMessage() on parritfAlarms, you should loop through arritfAlarmsFromAll and access each alarm instance correctly.

Corrected Code

// Declaration
arritfAlarmsFromAll : ARRAY [0 .. 20] OF IAlarm2;
sMessage : STRING;
parritfAlarms : POINTER TO ARRAY[0..15] OF IAlarm;
itfAlarmGroup : IAlarmGroup;
i : INT;

// Code
FOR i := 0 TO 15 DO
    IF arritfAlarmsFromAll[i] <> 0 THEN // Ensure alarm instance exists
        sMessage := arritfAlarmsFromAll[i].GetMessage(stringType := __SYSTEM.TYPE_CLASS.TYPE_STRING);
    END_IF
END_FOR

3. Additional Considerations

  • Ensure Alarms Exist: If arritfAlarmsFromAll does not contain active alarms, GetMessage() will likely cause an exception.
  • Index Out of Bounds: You’re using an array size of 20, but parritfAlarms points to a size of 16. Ensure they align.
  • Null Check: If parritfAlarms is 0, it should not be accessed.

Try this fix and let me know if the issue persists!