Skip to content

(Event Binding) General structure

Stephan Stricker edited this page Jul 8, 2019 · 10 revisions

Basics

An event binding consists of two main elements.

  • Event trigger

This is the source of the event. The following triggers can be define

  • Event handler

This is the part that gets executed when a trigger is fired. The event handler can vary depending on the complexity of the actions that are executed.

The following example shows a complete simple event binding. The source is the event trigger. In this case the change of a PLC variable. The event handler executes the action. The target is the active web session where a dialog window is opened.

<EventBinding>
  <!-- Trigger when button was pressed />-->	
  <Source xsi:type="widgets.brease.Button.Event" contentRefId="Content1" widgetRefId="Button1" event="Click"/>

  <!-- Set PLC variable to 42 />-->	
  <EventHandler>
    <Action>
      <Target xsi:type="opcUa.NodeAction" refId="::prg1:var1" >
        <Method xsi:type="opcUa.NodeAction.SetValueNumber" value="42" />
      </Target>
    </Action>
  </EventHandler>
</EventBinding>

Conditions

In some cases it can be necessary to combine the event trigger with additional conditions. For example a value should only be set if it is within a certain range. These conditions can be added to the event handler by adding the parameter condition. For details about comparison see this options. Boolean values use the notation "newValue" for true and "NOT newValue" for false.

Snippet

<!-- New value smaller 20, old value greater 10 />-->
<EventHandler condition="newValue &lt; 20 AND oldValue &gt; 10" >

Full example

<EventBinding id="eventBindingId" >
  <!-- Trigger when value changed />-->	
  <Source xsi:type="session.Event" refId="variable1" event="ValueChanged"/>

  <!-- Execute when new value is smaller 20 and old value was greater 10 />-->	
  <EventHandler condition="newValue &lt; 20 AND oldValue &gt; 10" >
    <Action>
      <Target xsi:type="opcUa.NodeAction" refId="::prg1:var1" >
        <Method xsi:type="opcUa.NodeAction.SetValueNumber" value="42" />
      </Target>
    </Action>
  </EventHandler>
</EventBinding>

Conditions from external sources

It is important to note that the conditions from the previous chapter are local. This means the data used in this condition was generated automatically by the event itself. The session event generates the variables newValue and oldValue. These variables can then be used in the condition later. If another variable is required, for example a PLC value, then it is necessary to actively read this value first. This can be done through ReadTarget. It is good practice to assign all external values to a local variable by using Operand.

Snippet

  <!-- Read additional value from PLC />-->	
  <Operand name="ContentIsVisible1" datatype="BOOL">
    <ReadTarget xsi:type="opcUa.NodeAction.Read" refId="::AsGlobalPV:Motor[1].IsVisible" >
      <Method xsi:type="opcUa.NodeAction.GetValue" />
    </ReadTarget>
  </Operand>

Full example

<EventBinding>
  <!-- Trigger when new content is loaded />-->	
  <Source xsi:type="clientSystem.Event" event="ContentLoaded" />

  <!-- Read additional value from PLC />-->	
  <Operand name="ContentIsVisible1" datatype="BOOL">
    <ReadTarget xsi:type="opcUa.NodeAction.Read" refId="::AsGlobalPV:Motor[1].IsVisible" >
      <Method xsi:type="opcUa.NodeAction.GetValue" />
    </ReadTarget>
  </Operand>

  <!-- Execute command when conditions are met />-->	
  <EventHandler condition="contentId=&quot;contentSample&quot; AND ContentIsVisible1=true" >
    <Action>
      <Target xsi:type="widgets.brease.ContentControl.Action" contentRefId="contentSample" widgetRefId="ContentControl1">
        <Method xsi:type="widgets.brease.ContentControl.Action.LoadContent" contentId="contentDyn1"/>
      </Target>
    </Action>
  </EventHandler>
</EventBinding>

Execute multiple actions

An event handler can execute multiple actions but they must be separated through sequence. To create a sequence use the parameter Sequence in combination with Step order. The actions are execute one after the other.

Snippet

<Sequence>
  <Step order="0">
    <Action>
      ...
    </Action>
  </Step>
  <Step order="1">
    <Action>
      ...
    </Action>
  </Step>
</Sequence>

Full example

<EventBinding>
    <Source xsi:type="widgets.brease.Button.Event" contentRefId="Content1" widgetRefId="Button1" event="Click"/>
    <EventHandler condition="" >
      <Sequence>
        <Step order="0">
          <Action>
            <Target xsi:type="opcUa.NodeAction" refId="::prg1:var1" >
              <Method xsi:type="opcUa.NodeAction.SetValueNumber" value="42" />
            </Target>
          </Action>
        </Step>
        <Step order="1">
          <Action>
            <Target xsi:type="opcUa.NodeAction" refId="::prg1:var2" >
              <Method xsi:type="opcUa.NodeAction.SetValueBool" value="true" />
            </Target>
          </Action>
        </Step>
      </Sequence>
    </EventHandler>
  </EventBinding>

Results of actions

Actions can also provide a result. This can be useful when the actions shows a message box that the use has to acknowledge. Use the parameter **Result **to add a result handler. The result is stored in the variable result. The result handler can then execute another action.

<EventBinding>
  <Source xsi:type="widgets.brease.Button.Event" contentRefId="Content1" widgetRefId="Button1" event="Click"/>
  <EventHandler condition="" >
    <Action>
      <Target xsi:type="clientSystem.Action" >
        <Method xsi:type="clientSystem.Action.ShowMessageBox" type="OKCancel" message="HelloWorld" header="Warning!" icon="Warning" />
      </Target>
      <Result>
        <ResultHandler condition="result = 4"> 
          <Action>
            <Target xsi:type="opcUa.NodeAction" refId="::prg1:var2" >
              <Method xsi:type="opcUa.NodeAction.SetValueNumber" value="11" />
            </Target>
          </Action>
        </ResultHandler>
      </Result>
    </Action>
  </EventHandler>
</EventBinding>
Clone this wiki locally