-
Notifications
You must be signed in to change notification settings - Fork 4
(Use case) Session variable to PLC and back to client session
- Automation Studio 4.4
- mappView 5.4
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.
- 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
Create a PLC variable array that is large enough to store the maximum number of session variables. Enable this array to the OPC configuration.
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>
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>
General Information
Direct binding
Event binding
Use cases
- General
- Widgets
- Styles
- Text
- Content