'TwinCat3 how to efficiently setup the EventLogger in an OOP?

I'm still very new to OOP and TwinCat so please bear with me. I'm currently developing the software for a small machine that will be used combined with the TF2000 HMI. Because the Event Grid takes away a lot of work I want to set up the TC3 EventLogger. I understand how you create alarms etc. and I can display them in the HMI Event Grid.

It works great with single events, but now I want to take it further and add the errors of every function block. For example FB_TemperatureController can report overheat, FB_Motor can report a stop error and so on.

How do I setup the event logger so I can send the same error from every instantiated FB?

I thought of creating a FB_FaultHandler:

FUNCTION_BLOCK FB_FaultHandler
VAR
    fbEventLogger       : FB_TcEventLogger;
    aMessages           : ARRAY [0..100] OF Fb_TcMessage;
    aAlarms             : ARRAY [0..100] OF Fb_TcAlarm;
END_VAR

METHOD init
VAR_INPUT
END_VAR

aAlarms[0].CreateEx(Tc_Events.AlarmEvents.Error_Overtemp, TRUE, 0);
aAlarms[1].CreateEx(Error2, TRUE, 0);
aAlarms[2].CreateEx(Error3, TRUE, 0);
aAlarms[3].CreateEx(Error4, TRUE, 0);
aAlarms[4].CreateEx(, TRUE, 0);
aAlarms[5].CreateEx(, TRUE, 0);
aAlarms[6].CreateEx(, TRUE, 0);

There's a few things I don't like about this tho:

  1. The source of the event would always be FB_FaultHandler but I want it to display the concerning FB
  2. I'm not sure how to raise an alarm from different instances twice. For example: fbTemp1 and fbTemp 2 are both instances of FB_TemperatureController. Now if I create a "SetFault" Method in the FB_FaultHandler, which raises and confirms an alarm it would raise the same error twice without me knowing the source.
METHOD setError
VAR_INPUT
  nErrorId: INT;
  bErrorActive: BOOL;
END_VAR
  1. I'd prefer if the array would be set up with the id of an event. So "Error_Overtemp" has id 96 and the FB_FaultHandler will put it in aAlarms[96]

I haven't really found any real samples about this anywhere. I watched the Webinar but it honestly is described very poorly. I'd be thankful for any help, input or examples of a good event logger.



Solution 1:[1]

I recommend looking at the documentation for attribute ‘instance-path’. This should tell you which instance of a function block is the source (Motor1 or Motor2). You will find source code example there.

https://infosys.beckhoff.com/content/1033/tc3_plc_intro/3108100107.html?id=5092968876405062789

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonny Tryhard