Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

How to read string from CharBufferPtr?

dtamm
2024-02-21
2024-02-21
  • dtamm - 2024-02-21

    I am trying to implement a mechanism to send alarm SMS. For this, I have created an Alarm Class with a Notification Action which calls a POU. This POU implements IAlarmNotifiable making it selectable in the Alarm Class configuration. IAlarmNotifiable has an Execute method which is called by the alarm class.
    Now, I want to extract the alarm message of the triggered alarm. The Execute method comes with a VAR_INPUT itfAlarm: AlarmManager.IAlarm which supplies a method called GetMessage. The help text says:

    Returns the message text, that has been configured for the alarm. The result is a pointer to the buffer, where the message text is stored

    The type of the result is CharBufferPtr, and at some place I read that it can be interpreted as a pointer to string. But I cannot manage to extract the alarm message, all I get are numbers. I have tried the following:

    psAlarmText := itfAlarm.GetMessage(__SYSTEM.TYPE_CLASS.TYPE_STRING)^;
    sAlarmText := TO_STRING( itfAlarm.GetMessage(__SYSTEM.TYPE_CLASS.TYPE_STRING)^ );
    

    So how do I get access to the alarm message as clear text? (In this case, "Larm 1")

     
  • dtamm - 2024-02-21

    Solved it! The simple answer was to declare a variable as POINTER TO STRING and assign the GetMessage result to that variable. Then, the ^ operator can be used to extract the message as string.

     

Log in to post a comment.