# Alarm Manager problem

**URL:** <https://www.wago.community/t/alarm-manager-problem/1663>\
**Category:** CODESYS\
**Created:** [March 12, 2025, 11:26am UTC](https://www.wago.community/t/alarm-manager-problem/1663 "2025-03-12T11:26:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![farta](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@farta](https://www.wago.community/u/farta)\
**Post date:** [March 12, 2025, 11:26am UTC](https://www.wago.community/t/alarm-manager-problem/1663/1 "2025-03-12T11:26:07Z")

</div>

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](https://us1.discourse-cdn.com/flex016/uploads/wago/optimized/2X/8/80d4c4936f3f19fe667e008cf414fc7a531562c0_2_690x47.png)

 ![2025-03-12_11h19_49](https://us1.discourse-cdn.com/flex016/uploads/wago/original/2X/4/45bd3fe592b14c8e15dd1edc3d603e8a44c2303f.png)  
 ![2025-03-12_12h23_35](https://us1.discourse-cdn.com/flex016/uploads/wago/original/2X/e/ea0175a7f87dfb42b8c1dc0d99353a1757759407.png)

* * *

1. SelectedRow+1 

2. SelectedRow+1

---

<div class="post-metadata">

**Author:** ![Jacob](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/jacob/32/642_2.png) [@Jacob](https://www.wago.community/u/Jacob)\
**Post date:** [March 16, 2025, 10:00pm UTC](https://www.wago.community/t/alarm-manager-problem/1663/2 "2025-03-16T22:00:53Z")

</div>

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**

```auto
// 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!
