Hello all, I am trying to work with Notifications in C++ and sending those to the PLC. But B cant seem to figure out how any of it works. I have been following along with the tutorial on github (CppExamples/Examples/NotificationExample/README.MD at master · PLCnext/CppExamples · GitHub) but i can’t wrap my head around the code or what it does. Could anyone explain how it works? Any help would be apriciated.
Hi Robin, By coincidence I was answering questions about this example for someone else this morning, so it’s fresh in my mind. The first thing is to understand the concept, and the relationship between the Notification Manager, notification publishers, notification subscribers, and (specifically) the Notification Logger component (which is a notification subscriber). The Info Center has a series of pages on this topic, starting here: https://www.plcnext.help/te/Service_Components/Notifications/Notification_manager.htm Are you able to briefly describe how you want to use notifications - e.g. do you want to publish notificiations, or subscribe, or both? If “publish”, do you have your own component where these notifications will be published from? Which component(s) will subscribe to these notifications? Once we have this background info, we can look at the parts of the code that do each of these things. ~ Martin.
Hi Martin, For my internship at Phoenix Contac Belgium i was tasked with sending custom notifications from C++ and making them show up in the online control panel of the plc. The person who gave me this task wanted to be able to make his own notifications and show them in the control panel.
OK, I understand. Is this assumption correct in your case? [quote]It is assumed that the user has some experience building C++ Components and Programs for PLCnext Control.[/quote] If not, then first you will need to get familiar with the process of creating and running PLCnext Components - either PLM components, or ACF components, depending on what type of component will be generating the notifications. If you have no preference, then a PLM component is slightly easier to deploy and instantiate (using PLCnext Engineer). There are tutorial videos in the Info Center, which include the procedure for creating a PLM component in Eclipse: https://www.plcnext.help/te/Tutorial_videos/Tutorial_videos_Cpp_programming.htm The procedure in Visual Studio, or using other IDEs, is similar. Once you are able to create, deploy and run a simple PLCnext Component, then we can start looking at the additional code needed to publish Notifications from that component.
That assuption is correct, i have made some simple components to read data from the PLC and edit it in C++. it’s just that these notifications make changed and do use code i don’t understand.
OK, great. So the next thing to decide is - will the notifications be generated from a Component, or from a Program? While only Components should receive notifications, it is possible to send notifications from either a Component or a Program. The example in Github sends non-blocking notifications from a Program, so if you have no preference then you could do the same. Next: Have you defined the payload for your custom notification in a .hpp file? This will need to be in a similar format to the ExamplePayload.hpp file in Github. If you need help defining the custom payload, please let us know: [list] [*]Your project namespace (“NotificationExample” in the example) [*]The name of your custom payload class (“ExamplePayload” in the example) [*]The list of methods that the custom payload should include (“GetMyValue” and “GetMyString” in the example) [*]The payload string - used to display a notification instance in “string” form (“The value is: {0}” in the example). [/list] If you simply want to use the same payload class as in the example, you only need to make sure that the project namespace in the .hpp file matches the namespace of your project. This custom payload class must otherwise follow the template given in the example. You can see that the custom payload class inherits from SpecializedPayload, which you can read more about here: https://api.plcnext.help/api_docs_2021-0-LTS/classArp_1_1System_1_1Nm_1_1SpecializedPayload.html We can go into more detail on this Payload class, if you want, or else we can move on to the code needed to send a notification (using this class) from your program.
thanks for the help so far, i would like to continue with sending the notification.
You have now defined a custom notification. The next step is to create everything needed to send this custom notification from your Program. Here, I am following Part 2 of the guide in Github: https://github.com/PLCnext/CppExamples/tree/master/Examples/NotificationExample#part-2—creating-custom-notifications That guide shows the code snippets that must be inserted into the program header file, with a description of each snippet. The resulting program header file is also linked in that section, and it has the modifications numbered with comments, 1 to 8. You will need to make the same 8 modifications to your program header file, adapted to your project e.g. if your custom payload header file is different, then this will need to change from “ExamplePayload.hpp”. If you have questions about any of these 8 changes in your Program Header file, please let us know. Otherwise, we can move on to the next section - Sending Notifications.
i did’t know they made all these other changes, i thought only the things in the tuttorial were changed. thanks for pointing this out. i would like to proceed with the next step please
The final step - sending notifications - is relatively simple. In this case the notifications are sent from the Program .cpp file. Here, I am following Part 3 of the guide in Github: https://github.com/PLCnext/CppExamples/tree/master/Examples/NotificationExample#part-3—sending-notifications That guide shows the code snippets that must be inserted into the program .cpp file, with a description of each snippet. The resulting file is also linked in that section. Like with the header file, there are more modifications than are shown in the README, e.g. a “now()” method has been added, to get the current system time in the correct format. In the “Execute()” method of the program .cpp file, one notification is sent every time the value of the port variable IP_uiInfoValue changes, and a second notification is sent every time the value of the port variable IP_uiWarningValue changes. Once this step is implemented successfully, along with the earlier steps, then your program will send notifications every time one or both of those port variables changes. Those port variables can be changed when you create an instance of this program in a PLCnext Engineer project. All notifications are published to the Notification Manager, but of course your notifications will only be seen by components that have subscribed to your notifications. Do you know where you want to see the notifications appear? e.g. in the PLCnext Engineer controller cockpit window? or on the Web-based Management page? or in your own custom component?
I have followed along and am ready for the following step, i would like to see it in the Web-based management page and/or the cockpit window.
The notifications shown in Web-Based Management, and in the cockpit window in PLCnext Engineer, are sourced from the notification database that is filled by the Notification Logger. The Notification Logger is a PLCnext Runtime component that subscribes to notifications. So, you want to configure the Notification Logger to subscribe to your custom notifications. The procedure for doing this is relatively simple, and is described in Part 5 of the tutorial on Github. This includes a link to more information in the Info Center, and a sample Notification Logger configuration file for the example project. Once your custom notification logger configuration is applied to the PLC (and the PLCnext Runtime is restarted), then all the custom notifications sent by your program should be logged by the notification logger, and they should also appear in WBM and in PLCnext Engineer.
i’m having toruble with this, i cant find the file /opt/plcnext/projects/Default/Services/NotificationLogger. it’s not specified where this is located. is it saved on my pc? on the plc? how do i get there?
From the tutorial: [quote]The default configuration files can be seen on the PLC, in the /opt/plcnext/projects/Default/Services/NotificationLogger directory. To apply a custom configuration file to the notification logger, additional configuration file(s) can be added to the /opt/plcnext/projects/Default/Services/NotificationLogger directory on the PLC, and the PLC restarted.[/quote] This directory is on the PLC. You will need to use WinSCP (or similar) to view and change files in this directory. This information in the Info Center may help: https://www.plcnext.help/te/Operating_System/Connecting_to_the_controller.htm
i have made the change but how do i test this? i am trying to use some physical buttons to simulate, making them generate a number or phrase but on the plc the ‘fail’ LED lights up immediately
The example in Github can be tested by creating an instance of the Program in PLCnext Engineer, and then (in Debug mode) manually changing the value of one of the Port variables IP_uiInfoValue or IP_uiWarningValue. If the program crashes - which it sounds like is happening here - please check the Output.log file (in the /opt/plcnext/logs directory) for messages. Also, if you have used Eclipse to develop the program, you can debug the program - setting breakpoints etc - to help find the problem.
from the log file it seems like the notifications aren’t being created and ‘Exception of type ‘Arp::System::Commons::InvalidOperationException’ was thrown’ is what i keep seeing
Going back a step: Does the Quick Start example run OK for you, when you follow the procedure in that section on Github? If so, then the notifications mechanism is in the PLCnext Runtime is working OK, and there must be something in your code that is different to the example, that is causing the exception.
when i try to build the example i get an error in the CLI: ‘Could not find the version ‘2021.0.0 LTS (21.0.0.35466)’ of the target ‘AXCF2152’. Available versions are: 21.0.2.35550.’ maybe this is because it was made in an earlier version?
Yes, you’re right. The tutorial was built using the first LTS version of the SDK, which we hoped would be valid for a year. But we obviously forgot about hot-fixes, so that SDK version is no longer available on our website. You will need to change the target that the project is built for, using the procedure in this Application Note: Knowledge Portal You will need to copy the complete text above and paste it into your browser - the hyperlink gets messed up in this forum (sorry). In this case there is no .vcproj file, but the commands should be run from the directory with the plcnext.proj file.