-
Notifications
You must be signed in to change notification settings - Fork 4
(Use case) Use mappAudit with mappView
- Introduction
- Requirements
- Basic Sample
- Using OPC events
- Using custom events
- Using the export function
- Appendix
This example -->sample<-- shows how to use mappAudit with mappView. mappAudit allows you to track a variety of events on the PLC like variable or user changes. For details about the events see the Automation Help file (7070eb76-adca-4842-bfee-9b225d8633a5). In this example we use the text system to create meaningful text for audit events.
If one of the pictures shown below is too small use right click and open in new window.
- Automation Studio 4.5
- mappView 5.71
- mappServices 5.71
Add mappAudit configuration to project
- Open the configuration view and select mappServices
- Drag and drop MpAuditTrail from the toolbox into the mappServices folder
- Open the new mappAudit configuration
- Change the text source to "TextSystem" and enter "MpAudit/Event/Root" for the text source format. (See Text Source for details about the text system)
- Select one or more PLC variables for testing
Add language support
Skip this step if the project already has a language configuration
- Switch to the logical view and select the top of the project
- Add "ProjectLanguages" from the toolbox
Add the mapp server
- Select the libraries folder
- Select B&R libraries in the toolbox
- Add the library "MpServer"
Add mpAudit function block call
This is the core function block that drives the audit server. It has to be called in a cyclic task.
- Create a new task or open an existing one
- Click on add library
- Select the function call MpAuditTrail
Only the two parameters "MpLink" and "Enable" are mandatory. Change the function block call to
MpAuditTrail_0(MpLink := ADR(gAuditTrail), Enable := 1);
Add the function block declaration
Add the sample text files
- Expand the library MpAudit. Select all files ending with tmx and copy the files
- Open the mappView visualization and paste all tmx files under Resources->Texts
Add data point information
Since in most cases the variable name itself has little meaning for the operator an alternative text can be defined for each variable in this text file. This is the variable name we defined here in step 3.
- Open the text file TxtDatapoints.tmx
-
- Use "::TestVar1" for the text ID and add a meaningful text for the variable
- For local variables use "::Program:TestVar3"
- For OPC variables use "::AsGlobalPV:TestVar3"
Add an audit container widget
Open the existing mappView visualization and add the AuditList widget
Add audit list data
Select the AuditList widget and add the AuditListItem
Bind audit list widget to mappView
- Select the AuditList widget and open the properties
- Click on the mpLink binding
- Open the tab "mapp"
- Select mpAudit configuration
Add text system configuration
Skip this step if you already have a text system configuration. Change to the configuration view.
- Switch to the configuration view. Select the TextSystem
- Add a text system configuration to the project
Configure text system
- Open the new text system configuration
- Select the System, Fallback language and add at least one Target language
- Select the text files mappView.Resources.Texts.TxtEvent.tmx and TxtDatapoints.tmx
Download the project and open the visualization and check if the value changes are tracked
To include OPC variables events the basic sample has to be changed.
Enable OPC server
- Open the PLC configuration
- Expand the OPC UA System
- Enable the OPC server, Auditing Server Facet and select a Security Admin
Enable OPC audit
- Open the mappAudit configuration
- Enable advanced settings
- In the last event (grey) select "OPC/UA Value-changes"
OPC tag configuration
- Open the OpcUA tag configuration
- Select the OPC variable that should be audited
- Enable the variable for OPC access
- Enable auditing the variable in the properties
Define variable text
- Open the text file TxtDatapoints.tmx
- Enter "::Program:TestVar3" for the TextID and add a meaningful text for the variable
Add an input field for TestVar3 to the mappView visualization. Download the project and open the visualization.
To include custom events the basic sample has to be changed.
Add function call
- Open the sample task
- Add the following code and define a new variable "TestVar3old" of type REAL
// Create a custom event when TestVar3 is 0`
`IF(TestVar3 = 0 AND TestVar3old <> 0) THEN`
`MpAuditCustomEvent(MpLink := gAuditTrail, Type := "ValueChange", Message := "Test Variable 3 was set to 0", Comment := "");`
`END_IF`
`TestVar3old := TestVar3;
Add text information
- Open the text file mappView.Resources.Texts.TxtCustom.tmx
- Enter "ValueChange" for the text ID and for the languages [%msg]
Add text file
- Switch to the configuration view and open the text configuration
- Add the TxtCustom file to the list
Download the project and open the visualization. When you set the TestVar3 to 3 and back 0 a new custom event is triggered.
To export the audit events the basic sample has to be changed.
Add a file device
This is where the text file with the audit information is stored.
- Open the the physical view and open the PLC configuration
- Add a new file device and point to a folder
Change the mappAudit function block call
- Open the logical view and open the task
- Add the device information and trigger for the export to the function block call. Define a new variable "cmdExport" of type BOOL
// Main function call for mappAudit
MpAuditTrail_0(MpLink := ADR(gAuditTrail), Enable := 1, DeviceName := ADR('HD'), Export := cmdExport);
cmdExport := FALSE;
Add a button in the visualization
- Open the mappView visualization
- Add a new button, change the name of the button to "btnExport"
- Switch to the event properties
- Click into the "click" event
The default window for the event bindings will open. Make sure the event binding file is the correct one and is listed in the visualization configuration. Add the following code for the event.
<EventBinding id="contentStart.btnExport.Click">
<Source contentRefId="contentStart" widgetRefId="btnExport" xsi:type="widgets.brease.Button.Event" event="Click" />
<EventHandler>
<Action>
<Target xsi:type="opcUa.NodeAction" refId="::Program:cmdExport" >
<Method xsi:type="opcUa.NodeAction.SetValueBool" value="true" />
</Target>
</Action>
</EventHandler>
</EventBinding>
Change the OPC configuration
- Switch to the configuration view and open the OPC configuration
- Select the variable cmdExport
- Enable the variable with the green check mark
Change the mappAudit configuration
- Open the mappAudit configuration
- Change the encryption to false to make the file readable
Download the project and open the visualization. Use the button to export the current audit data.
The text used in mappAudit is provide by a collection of text files (tmx). In the basic sample these text files are located in the mappView visualization. In many cases the text is combined from multiple text files. The entry point for the text used in mappAudit defined in the mappAudit configuration (2). In this example entry point is in the file TxtEvent.tmx (1). The primary message is defined in Root. Root references text depending on the event type (3). For details about the events see the Automation Help file (7070eb76-adca-4842-bfee-9b225d8633a5). Since the variable name used in the PLC makes very little sense to the operator a more meaningful name can be defined for each variable that is audited. This definition is stored in the file TxtDatapoints.tmx.
Question: Why do I get entries like "Value changed from old value 5 to new value 5"
Answer: When you use the function to generate a value changed entry this is logged even if old and new value are identically. When you connect a variable to an input widget, open the numeric touchpad and just hit enter without changing the value an audit event is generated as well.
General Information
Direct binding
Event binding
Use cases
- General
- Widgets
- Styles
- Text
- Content