Skip to content

(Use case) Session variable to PLC and back to client session

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

Requirements

  • Automation Studio 4.4
  • mappView 5.4

Description

This example -->sample<-- shows how to exchange information from a session variable to the PLC and back. Keep in mind that session variables exist ones for each session. Therefore an array has to be used on the PLC side. In the following example a maximum of 3 sessions are handled.

Implementation

  • Configuration of a PLC array that reflects the different session variables
  • Configuration of a list binding that stores the information in the PLC variables array
  • Configuration of an event binding that connects the PLC variables array to the session variables

Configuration of a PLC array that reflects the different session variables

Create a PLC variable array that is large enough to store the maximum number of session variables. Enable this array to the OPC configuration.

Configuration of a list binding that stores the information in the PLC variable array

In the following list binding, the client session variables is connected to a variable array on the PLC. By using "slotId" as the selector, each client writes to the array element corresponding to its slot ID.

<Binding mode="oneWayToSource">
  <Source xsi:type="listElement">
    <Selector xsi:type="session" refId="::SYSTEM:clientInfo.slotId" attribute="value" />
	<be:List xsi:type="be:opcUa" attribute="value">
	  <bt:Element index="0" refId="::AsGlobalPV:SessionPLC[0]" />
	  <bt:Element index="1" refId="::AsGlobalPV:SessionPLC[1]" />
	  <bt:Element index="2" refId="::AsGlobalPV:SessionPLC[2]" />
	</be:List>
  </Source>
  <Target xsi:type="session" refId="SessionVar" attribute="value" />
</Binding>

Configuration of an event binding that connects the PLC variable array to the session variables

In the following event binding, variable array on the PLC is connected to the client session variables.

		
<EventBinding>
    <!-- Trigger when new value />-->
    <Source xsi:type="opcUa.Event" refId="::AsGlobalPV:SessionPLC[0]" event="ValueChanged" />
    <!-- Read additional value from PLC />-->
    <Operand name="slotId" datatype="ANY_INT">
        <ReadTarget xsi:type="session.VariableAction.Read" refId="::SYSTEM:clientInfo.slotId" >
            <Method xsi:type="session.VariableAction.GetValue" />
        </ReadTarget>
    </Operand>
    <!-- Execute command when conditions are met />-->
    <EventHandler condition="slotId=0" >
        <Action>
            <Target xsi:type="session.VariableAction" refId="SessionVar" >
                <Method xsi:type="session.VariableAction.SetValueNumber" value="=newValue" />
            </Target>
        </Action>
    </EventHandler>
</EventBinding>
<EventBinding>
    <!-- Trigger when new value />-->
    <Source xsi:type="opcUa.Event" refId="::AsGlobalPV:SessionPLC[1]" event="ValueChanged" />
    <!-- Read additional value from PLC />-->
    <Operand name="slotId" datatype="ANY_INT">
        <ReadTarget xsi:type="session.VariableAction.Read" refId="::SYSTEM:clientInfo.slotId" >
            <Method xsi:type="session.VariableAction.GetValue" />
        </ReadTarget>
    </Operand>
    <!-- Execute command when conditions are met />-->
    <EventHandler condition="slotId=1" >
        <Action>
            <Target xsi:type="session.VariableAction" refId="SessionVar" >
                <Method xsi:type="session.VariableAction.SetValueNumber" value="=newValue" />
            </Target>
        </Action>
    </EventHandler>
</EventBinding>
<EventBinding>
    <!-- Trigger when new value />-->
    <Source xsi:type="opcUa.Event" refId="::AsGlobalPV:SessionPLC[2]" event="ValueChanged" />
    <!-- Read additional value from PLC />-->
    <Operand name="slotId" datatype="ANY_INT">
        <ReadTarget xsi:type="session.VariableAction.Read" refId="::SYSTEM:clientInfo.slotId" >
            <Method xsi:type="session.VariableAction.GetValue" />
        </ReadTarget>
    </Operand>
    <!-- Execute command when conditions are met />-->
    <EventHandler condition="slotId=2" >
        <Action>
            <Target xsi:type="session.VariableAction" refId="SessionVar" >
                <Method xsi:type="session.VariableAction.SetValueNumber" value="=newValue" />
            </Target>
        </Action>
    </EventHandler>
</EventBinding> 
Clone this wiki locally