Skip to content

(Use case) Use mappAudit with mappView

Stephan Stricker edited this page Apr 21, 2020 · 4 revisions

Table of Contents

Description

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.

Requirements

  • Automation Studio 4.5
  • mappView 5.71
  • mappServices 5.71

Basic Sample

Add mappAudit configuration to project

  1. Open the configuration view and select mappServices
  2. Drag and drop MpAuditTrail from the toolbox into the mappServices folder

Image


Configure mappAudit

  1. Open the new mappAudit configuration
  2. 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)
  3. Select one or more PLC variables for testing

Image


Add language support

Skip this step if the project already has a language configuration

  1. Switch to the logical view and select the top of the project
  2. Add "ProjectLanguages" from the toolbox

Image


Add the mapp server

  1. Select the libraries folder
  2. Select B&R libraries in the toolbox
  3. Add the library "MpServer"

Image


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.

  1. Create a new task or open an existing one
  2. Click on add library
  3. Select the function call MpAuditTrail

Image

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

Image


Add the sample text files

  1. Expand the library MpAudit. Select all files ending with tmx and copy the files
  2. Open the mappView visualization and paste all tmx files under Resources->Texts

Image


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.

  1. 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"

Image


Add an audit container widget

Open the existing mappView visualization and add the AuditList widget Image


Add audit list data

Select the AuditList widget and add the AuditListItem Image


Bind audit list widget to mappView

  1. Select the AuditList widget and open the properties
  2. Click on the mpLink binding
  3. Open the tab "mapp"
  4. Select mpAudit configuration

Image


Add text system configuration

Skip this step if you already have a text system configuration. Change to the configuration view.

  1. Switch to the configuration view. Select the TextSystem
  2. Add a text system configuration to the project

Image


Configure text system

  1. Open the new text system configuration
  2. Select the System, Fallback language and add at least one Target language
  3. Select the text files mappView.Resources.Texts.TxtEvent.tmx and TxtDatapoints.tmx

Image


Download the project and open the visualization and check if the value changes are tracked Image


Using OPC variables events

To include OPC variables events the basic sample has to be changed.

Enable OPC server

  1. Open the PLC configuration
  2. Expand the OPC UA System
  3. Enable the OPC server, Auditing Server Facet and select a Security Admin

Image


Enable OPC audit

  1. Open the mappAudit configuration
  2. Enable advanced settings
  3. In the last event (grey) select "OPC/UA Value-changes"

Image


OPC tag configuration

  1. Open the OpcUA tag configuration
  2. Select the OPC variable that should be audited
  3. Enable the variable for OPC access
  4. Enable auditing the variable in the properties

Image


Define variable text

  1. Open the text file TxtDatapoints.tmx
  2. Enter "::Program:TestVar3" for the TextID and add a meaningful text for the variable

Image

Add an input field for TestVar3 to the mappView visualization. Download the project and open the visualization.


Custom Events

To include custom events the basic sample has to be changed.

Add function call

  1. Open the sample task
  2. 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;

Image


Add text information

  1. Open the text file mappView.Resources.Texts.TxtCustom.tmx
  2. Enter "ValueChange" for the text ID and for the languages [%msg]

Image


Add text file

  1. Switch to the configuration view and open the text configuration
  2. Add the TxtCustom file to the list

Image

Download the project and open the visualization. When you set the TestVar3 to 3 and back 0 a new custom event is triggered.


Using the export function

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.

  1. Open the the physical view and open the PLC configuration
  2. Add a new file device and point to a folder

Image


Change the mappAudit function block call

  1. Open the logical view and open the task
  2. 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;

Image


Add a button in the visualization

  1. Open the mappView visualization
  2. Add a new button, change the name of the button to "btnExport"
  3. Switch to the event properties
  4. 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>

Image


Change the OPC configuration

  1. Switch to the configuration view and open the OPC configuration
  2. Select the variable cmdExport
  3. Enable the variable with the green check mark

Image


Change the mappAudit configuration

  1. Open the mappAudit configuration
  2. Change the encryption to false to make the file readable

Image

Download the project and open the visualization. Use the button to export the current audit data.


Appendix

Text Source

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.

Image

FAQs

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.

Clone this wiki locally