Skip to content

OPC UA in IEC 61131-3: Alarms & Conditions / ALM_State / ALM_CUSTOM_ALARM

edited June 2023 in PLCnext Engineer

Hello community,

I am currently working on a project where i want to use OPC UA alarming. I have found some usefull informations to this topic:

OPC UA in IEC 61131-3: Alarms & Conditions - PLCnext Community (plcnext-community.net)

Alarm Function Blocks (IEC61131) (plcnext-community.net)

First step is to register all alarms to the OPC UA Server. Because i expect a larger amount of alarms i have created an function block for this. To send a registration i am using the Method SendAddAlarm from fb ALM_CUSTOM_ALARM. I am using an array to store all alarm structs. The registration looks something like this:


So far so good. I can see all registered alarms at my OPC Testclient. But now i want to activate an alarm. I tried to call an instance of ALM_REGISTER in the main Program. But this caused infinite number of OPC messages:





I couldn't figure out why. So i decidet to build an function block using the fb ALM_CUSTOM_ALARM.

At least i could get this working. Changes of the active state are puplished to the OPC server. No infinite number of masseges is shown. The problem is acknowledgement and confirmation is not working. About 1 sec after i set the alarm to "active", ACKED_STATE and CONFIRMED_STATE is True again (in the local ALM_STATE structure). But on the client side it still looks like this:

Calling acknowledge or confrim on the client side, has no effect… Has anyone an Idea how to solve this problem?

Comments

  • This Makers Blog was posted by a community member a while back:

    It includes a simple example that uses the Alarm function blocks in PLCnext Engineer. Maybe that example can help you to find the issue in your application. If not, please let us know.

  • Thank you for the hint, but i already found that example. It hastn't helped to find a solution. In that example only one alarm is used. I Think one of the main challenges is to register multiple alarms simultaneously in a smart way.

    And it is not shown how the ALM_ALARM fb is called. In the documentation it says you should call it all the time, but then i get these infinite number of OPC messages...

  • Ah, I now see that you posted a link to that Makers Blog in your original message. I missed that, sorry.

    The Makers Blog example worked for me. In the third example, the alarm was registered and one instance of the alarm was generated on every transition of the " ACTIVE" input from FALSE to TRUE. Keeping the ACTIVE input TRUE did not generate multiple alarm instances, like you are seeing.

    There should be a separate instance of the ALM_ALARM function block for each registered alarm. Trying to multiplex one instance of that FB for all registered alarms will be quite complicated and error-prone, and is probably the reason for the behaviour you're seeing.

    Also, I don't think that you are supposed to set the elements of each AlarmStruct directly, like you're doing. The elements of this struct are set using the parameters on the ALM_REGISTER function block. But if you're able to register the alarms successfully in this way, then maybe it's OK.

    Please try starting from the Makers Blog example, with a separate instance of each FB for each alarm. That should work OK. If you want to try and streamline the registration process using a single ALM_REGISTER FB instance, then that should work. But you should keep a separate ALM_ALARM FB instance for each alarm. If that doesn't work, then please let us know.

  • When i started my tests i tried to use one instance of ALM_REGISTER to register all Alarms at once (if done is true). But i couldn't get it running. Only the first alarm was registered correct. Thats why i started to test the Methods of ALM_CUSTOM_ALARM. If you are using these there is no other chance than writing values direktly to the ALM structure.

    Registration is working correct at the moment, at least i think so. But i am worried if there could be some traps, because the  ALM_REGISTER has a "Done" output. The documetation says you shut wait if done is false. So there must be some reasons to wait sometimes, which I don't pay attention to at the moment. Because with the method call there is no "done" signal. So i will try again to use ALM_REGISTER . Or is there any futher information available when and why you need to wait?

    But after some pain i finally found a misstake i made.

    This is how i called my registration fb:

    I thought the ALM-Structure is only manupilated once at startup (R_TRIG). But I have forgotten that the fb then always writes the last state of the structure to the output. That was the reason for my infinite number of OPC messages. Because the structure always get reinitialized.

    I changed AlarmStruct to In/Out and now the messages are gone!


    So now i managed to use the ALM_ALARM fb.  Acknowledgement and confirmation is now working too (if you use the methods you also have to use GetAckConfRequest to get Ack and Conf)


    I hope that will help others to avoid such mistakes.

    Thank you very much. If i am completly done with this task i will post the hole solution. Maybe others will struggle too with this topic.

Sign In or Register to comment.