Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

TQL Engine supports OPC-UA protocol Handler, that can be used to subscribe/update various nodes present on OPC-UA server.


  OPCUA Protocol Handler Flow:

...

Parameter Name

Parameter Description

ConnectionConfig

A def containing all the information about connection and security parameters of OPCUA server, it has the following fields ServerUri, SecurityConfig and SecurityMode (0-6).

Security Mode             Description

0                                                  None

1                                                  128-bit RSA Sign

2                                                  128-bit RSA Sign and encrypt

3                                                  256-bit Basic Sign

4                                                  256-bit Basic Sign and encrypt

5                                                  256-bit SHA Sign

6                                                  256-bit SHA Sign and encrypt 

SecurityConfig

A def containing information about security parameters of the server, it has the following fields UserName, Password, ApplicationIdentity and CertificationParameters.

ApplicationIdentity

A def Containing information about the client’s Idenitiy, it has following fields AppName, AppUri and ProductUri.

CertificationParameters

A def containing information about the connection’s certificate parameters, it has following parameters     OrgName, Path, PrivateKeyPwd, ValidityInDay, AutoCertificateRenewal and KeySize.

Operation

This field specifies the operation to be performed, the operation are subscription and write.

NodeID

This parameter is used in case of write Operation, the Node ID on which the write operation is to be performed.

AttributeID

This parameter is used in case of write Operation, the Attribute ID of the respective Node ID on  which the write operation is to be performed.

OpcData

This parameter is used in case of write Operation, and this specifies the write value.

OPCUaSubscribe

A def specific to subscribe operation, It has fields like      NodeID: the Node Id to which we need to subscribe.

AttributeID: attribute ID is optional for subscription.

SubscribeChild: Whether you want to subscribe to child nodes also.

...


Usage of opcua protocol handler:

  • Opcua Write:

    Code Block
    languagexml
    titleOpcua Write Facet
    linenumberstrue
      <ThingFacet Name="OPCWriteFacet">
        <String Name="OpcData" KnownBy="OPCSubscriberAction"/>
        <String Name="NodeID"/>
        <Integer Name="AttributeID"/>
        <String Name="Operation"/>
        <ConnectionConfig Name="OPCWriteConnectionConfig"/>
        <Action Name="OPCSubscriberAction">
          <Workflow Limit="1" Live="1" Timeout="-1">
            <Task name="Main" >
              <Event as="ActionArgument" name="Argument"/>
              <Invoke get="opcua://" waitFor="Argument" name="InvokeOPCWrite" Operation="[%:Event.Argument.Operation.Value:%]" 
                ServerUri="[%:Event.Argument.OPCWriteConnectionConfig.ServerUri.Value:%]" 
                SecurityMode="[%:Event.Argument.OPCWriteConnectionConfig.SecurityMode.Value:%]" 
                UserName="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.UserName.Value:%]"
                Password="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.Password.Value:%]"
                Path="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.CertificationParameters.Path.Value:%]"
                ValidityInDay="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.CertificationParameters.ValidityInDay.Value:%]"
                AutoCertificateRenewal="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.CertificationParameters.AutoCertificateRenewal.Value:%]"
                PrivateKeyPwd="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.CertificationParameters.PrivateKeyPwd.Value:%]"
                OrgName="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.CertificationParameters.OrgName.Value:%]"
                KeySize="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.CertificationParameters.KeySize.Value:%]"
                AppUri="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.ApplicationIdentity.AppUri.Value:%]"
                AppName="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.ApplicationIdentity.AppName.Value:%]"
                ProductUri="[%:Event.Argument.OPCWriteConnectionConfig.SecurityOptions.ApplicationIdentity.ProductUri.Value:%]"
                NodeID="[%:Event.Argument.NodeID.Value:%]"
                AttributeID="[%:Event.Argument.AttributeID.Value:%]">
                <Message>
                  <Value>
                    "[%:Event.Argument.opcData.Value:%]"
                  </Value>
                </Message>
              </Invoke>
              <Output As="ActionResult" Name="Result">
                <Value>
                  <OpcData>[%:Invoke.InvokeOPCWrite.Message.Value:%]</OpcData>
                </Value>
              </Output>
            </Task>
          </Workflow>
        </Action>
      </ThingFacet>
    Code Block
    languagexml
    titlewrite Initialization Query
    linenumberstrue
    <Query>
      <DeleteAll>
        <OPCWriteModel>
          <writeId ne=""/>
        </OPCWriteModel>
      </DeleteAll>
      <Create>
        <OPCWriteModel>
          <Operation>
            Write
          </Operation>
          <OPCWriteConnectionConfig>
            <ServerUri>
              opc.tcp://MSEDGEWIN10:49320
            </ServerUri>
            <SecurityMode>
              2
            </SecurityMode>
            <SecurityOptions>
              <UserName/>
              <Password/>
              <ApplicationIdentity>
                <AppName>
                  atomitonClient@localhost
                </AppName>
                <AppUri>
                  urn:localhost:OPCUATQL
                </AppUri>
                <ProductUri>
                  urn:atomiton.com:OPCUA
                </ProductUri>
              </ApplicationIdentity>
              <CertificationParameters>
                <OrgName>
                  atomiton
                </OrgName>
                <Path>
                  /atomiton/certs
                </Path>
                <PrivateKeyPwd>
                  tql123#
                </PrivateKeyPwd>
                <ValidityInDay>
                  3650
                </ValidityInDay>
                <AutoCertificateRenewal>
                  true
                </AutoCertificateRenewal>
                <KeySize>
                  2048
                </KeySize>
              </CertificationParameters>
            </SecurityOptions>
          </OPCWriteConnectionConfig>
          <NodeID>
            ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_FCU_Temperature
          </NodeID>
          <AttributeID>
            13
          </AttributeID>
          <OpcData>
            1024
          </OpcData>
        </OPCWriteModel>
      </Create>
    </Query>
    Code Block
    languagexml
    titleWrite Update query
    linenumberstrue
    <Query>
      <Find format="version,known">
        <OPCWriteModel>
          <writeId ne=""/>
        </OPCWriteModel>
      </Find>
      <if condition="$Response.Message.Value/Find/Status eq 'Success'">
        <then>
          <SetResponseData>
            <key>
              Message.Value.Find.Result.OPCWriteModel.OpcData.Value
            </key>
            <value>
              200
            </value>
          </SetResponseData>
          <Update>
            <from>
              Result
            </from>
            <Include>
              $Response.Message.Value.Find
            </Include>
          </Update>
        </then>
      </if>
    </Query>
  • Opcua Subscription:

    Code Block
    languagexml
    titleOpcua Subscription Facet
    linenumberstrue
    	<Def Name="CertificationParams">
            <String Name="OrgName"/>
            <String Name="Path"/>
            <String Name="PrivateKeyPwd"/>
            <String Name="ValidityInDay"/>
            <String Name="AutoCertificateRenewal"/>
            <Integer Name="KeySize"/>           
        </Def>
        
        <Def Name="AppIdentity">
            <String Name="AppName"/>
            <String Name="AppUri"/>
            <String Name="ProductUri"/>
        </Def>
    
        <Def Name="SecurityConfig">
            <String Name="UserName"/>
            <String Name="Password"/>
            <AppIdentity Name="ApplicationIdentity"/> 
            <CertificationParams Name="CertificationParameters"/>       
        </Def>    
    
        <Def Name="ConnectionConfig">
            <String Name="ServerUri"/>
            <Integer Name="SecurityMode"/>  
            <SecurityConfig Name="SecurityOptions"/>     
        </Def>
    
        <Def Name="OPCUaSubscribe">
          <String Name="NodeID" Cardinality="0..m"/>
          <String Name="AttributeID"/>
          <String Name="SubscribeChild"/>
        </Def> 
     
        <ThingFacet Name="OPCSubscriberFacet">
         	 <String NameFormat="SubscriptionData$ObjectFormat(xml)" updateName="autoSubscriptionPayload" KnownBy="OPCSubscriberAction" update="auto"/>
    	<String Name="SubscriptionPayload" Format="$ObjectFormat(xml)" />
    	      <String Name="Operation" />
         	 <ConnectionConfig Name="OPCSubscribeConnectionConfig" />
    	      <OPCUaSubscribe Name="OPCSubscriptionConfig" />
    	
          <Action Name="OPCSubscriberAction">
    		
            <Workflow Limit="1" Live="1" Timeout="-1">
    			<Task           <Task name="Main" while="true">
    				
                <Event as="ActionArgument" name="Argument" />
    				<Invoke get="opcua://Subscribe" scope="process" waitFor="Argument"
    					name="InvokeOPCSubscription" Operation
                <Invoke AppName="[%:Event.Argument.Operation.OPCSubscribeConnectionConfig.SecurityOptions.ApplicationIdentity.AppName.Value:%]" 					ServerUri="
    AppUri="[%:Event.Argument.OPCSubscribeConnectionConfig.ServerUriSecurityOptions.ApplicationIdentity.AppUri.Value:%]"
    					SecurityMode 
    AutoCertificateRenewal="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParameters.SecurityModeAutoCertificateRenewal.Value:%]"
    					UserName 
    KeySize="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParameters.UserNameKeySize.Value:%]" 					Password
    OPCSubscriptionConfig="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.Password.ValueOPCSubscriptionConfig:%]" 					Path
    Operation="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParameters.PathOperation.Value:%]"
    					ValidityInDay 
    OrgName="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParameters.ValidityInDayOrgName.Value:%]"
    					AutoCertificateRenewal 
    Password="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParameters.AutoCertificateRenewalPassword.Value:%]"
    					PrivateKeyPwd 
    Path="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParameters.PrivateKeyPwdPath.Value:%]"
    					OrgName 
    PrivateKeyPwd="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParameters.OrgNamePrivateKeyPwd.Value:%]" 					KeySize
    ProductUri="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.CertificationParametersApplicationIdentity.KeySizeProductUri.Value:%]"
    					AppUri 
    SecurityMode="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.ApplicationIdentity.AppUriSecurityMode.Value:%]" 					AppName
    ServerUri="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptionsServerUri.ApplicationIdentity.AppName.Value:%]"
    					ProductUriUserName="[%:Event.Argument.OPCSubscribeConnectionConfig.SecurityOptions.ApplicationIdentityUserName.ProductUri.Value:%]" 					NodeID
    ValidityInDay="[%:Event.Argument.OPCSubscriptionConfigOPCSubscribeConnectionConfig.NodeID.ValueSecurityOptions.CertificationParameters.ValidityInDay.Value:%]" 					AttributeID
    get="[%:Event.Argument.OPCSubscriptionConfig.AttributeID.Value:%]"
    					SubscribeChild="[%:Event.Argument.OPCSubscriptionConfig.SubscribeChild.Value:%]" />
    				<Invoke name="SaveDataopcua://Subscribe" name="InvokeOPCSubscription" scope="process" waitFor="Argument"/>
    					<FacetScript> 						<executeQuery> 							<QueryString>
    								<Query>
    									<Find format="version,known">
    										<OPCSubscriberModel>
    											<subscribeId eq="[%:Event.Argument.subscribeId:%]" />
    										</OPCSubscriberModel>
    									</Find>
    									<if condition="$Response.Message.Value/Find/Status eq 'Success'">
    										<then>
    											<SetResponseData>
    												<key>
    													Message.Value.Find.Result.OPCSubscriberModel.SubscriptionPayload.Value
    												</key>
    												<value>
    													<Include>
    														Invoke.InvokeOPCSubscription.Message.Value
    													</Include>
    												</value>
    											</SetResponseData>
    											<Update>
    												<from>
    													Result
    												</from>
    												<Include>
    													$Response.Message.Value.Find
    												</Include>
    											</Update>
    										</then>
    									</if>
    								</Query>
    							</QueryString>
    						</executeQuery>
    					</FacetScript>
    				</Invoke>
    				<Output As="ActionResult" Name="Result">
    					<Value>
    						<SubscriptionData>Saved</SubscriptionData>
    					</Value>
    				</Output>
    			</Task>
    		</Workflow>
    	</Action>
              <Output As="ActionResult" Name="Result">
                  <Value>
                    <SubscriptionPayload>
                      <Include>Invoke.InvokeOPCSubscription.Message.Value</Include>
                    </SubscriptionPayload>
                  </Value>
                </Output>
              </Task>
            </Workflow>
          </Action>
        </ThingFacet>

    Note: The output is stored in the variable SubscriptionPayload although the Known By is on the variable SubscriptionData, this has been done to preserve the Xml structure and avoid TP processing. 

    Code Block
    languagexml
    titleSubscription Initialization Query
    linenumberstrue
    <Query>
      <DeleteAll>
        <OPCSubscriberModel>
          <subscribeId ne=""/>
        </OPCSubscriberModel>
      </DeleteAll>
      <Create>
        <OPCSubscriberModel>
          <Operation>
            subscription
          </Operation>
          <OPCSubscribeConnectionConfig>
            <ServerUri>
              opc.tcp://MSEDGEWIN10:49320
            </ServerUri>
            <SecurityMode>
              2
            </SecurityMode>
            <SecurityOptions>
              <UserName/>
              <Password/>
              <ApplicationIdentity>
                <AppName>
                  atomitonClient@localhost
                </AppName>
                <AppUri>
                  urn:localhost:OPCUATQL
                </AppUri>
                <ProductUri>
                  urn:atomiton.com:OPCUA
                </ProductUri>
              </ApplicationIdentity>
              <CertificationParameters>
                <OrgName>
                  atomiton
                </OrgName>
                <Path>/atomiton/certs</Path>
                <PrivateKeyPwd>
                  tql123#
                </PrivateKeyPwd>
                <ValidityInDay>
                  3650
                </ValidityInDay>
                <AutoCertificateRenewal>
                  true
                </AutoCertificateRenewal>
                <KeySize>
                  2048
                </KeySize>
              </CertificationParameters>
            </SecurityOptions>
          </OPCSubscribeConnectionConfig>
          <OPCSubscriptionConfig>
            <NodeID>
              ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1
            </NodeID>
            <AttributeID/>
            <SubscribeChild>
              true
            </SubscribeChild>
          </OPCSubscriptionConfig>
         
    <SubscriptionData>$Null()</SubscriptionData>       <SubscriptionPayload>$Null()</SubscriptionPayload>
        </OPCSubscriberModel>
      </Create>
    </Query>
    Code Block
    languagexml
    titleSubscription Deletion Query
    linenumberstrue
    <Query>
      <DeleteAll>
        <OPCSubscriberModel>
          <subscribeId ne=""/>
        </OPCSubscriberModel>
      </DeleteAll>
    </Query>
  • Note: It is possible to subscribe to multiple root nodes using a single facet, separate the NodeID's with ;; delimiter in subscription initialization query as shown below

    Code Block
    languagexml
    titleMultiple topics subscription
    linenumberstrue
    		 <NodeID>
              ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1;;ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank2
            </NodeID>

     

Opcua Subscription Message Output Format: The output message of opcua subscription is an xml structure that has array of opcua nodes as shown below.


 

Code Block
languagexml
titleXml Output Format
linenumberstrue
  <SubscriptionPayload Version="2">
        <Value>
          <OpcUaNodes>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_Agitator_Motor_Running_Bit</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_FCU_Temperature</NodeID>
              <NodeValue>201.0</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Float</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_Gallon_Value</NodeID>
              <NodeValue>1.34646997E15</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Double</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_Loading_PP_Motor_Running_Bit</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_RAW_Level_Inches</NodeID>
              <NodeValue>568.0</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Double</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_steaming_in_auto_selected_HMI</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_unld_PP_Motor_Running_Bit</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
          </OpcUaNodes>
        </Value>
        <Known>
          <OpcUaNodes>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_Agitator_Motor_Running_Bit</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_FCU_Temperature</NodeID>
              <NodeValue>201.0</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Float</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_Gallon_Value</NodeID>
              <NodeValue>1.34646997E15</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Double</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_Loading_PP_Motor_Running_Bit</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_RAW_Level_Inches</NodeID>
              <NodeValue>568.0</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Double</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_steaming_in_auto_selected_HMI</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
            <OpcUaNode>
              <ServerTimeStamp/>
              <NodeID>ns=2;s=Vopak.Device1.TankData.USSAV1S01HST.Tank1.Tank_1_unld_PP_Motor_Running_Bit</NodeID>
              <NodeValue>false</NodeValue>
              <StatusCode>GOOD</StatusCode>
              <SourceTimeStamp>08/10/16 00:38:27.0823950 GMT</SourceTimeStamp>
              <DataType>Boolean</DataType>
            </OpcUaNode>
          </OpcUaNodes>
        </Known>
      </SubscriptionPayload>