Skip to content

Step 6: Writing a OPC UA ModelDesign File

Last updated on September 1, 2020


This post shows how to write the model by editing a ModelDesign file with a suitable editor

This Post is part of the OPC UA Information Model Tutorial.


Recommendation

It is recommended that you also read through the following page to get an overview on OPC UA Information modeling:

How to create custom OPC UA Information Models

In this tutorial we are using the example files provided in the following repository:
https://github.com/pro/opcua-modeling-tutorial

Especially the file FooFltModel.xml

A more complete example with heavy use of heavy usage of ModelDesign files and dependencies between them is shown in this project (look into subfolders with the name opcua):

https://github.com/opcua-skills/plug-and-produce

Prerequisite

If you are using Visual Studio, make sure that you set up Visual Studio as mentioned here:

Step 3: Setup Visual Studio as ModelDesign Editor

Namespaces

Namespaces help to avoid naming conflicts by prefixing them to variable names. Apart from that, they also split the whole address space in the server into multiple groups.

The following code shows the minimum code required for an empty ModelDesign with comments indicating the designated model components. A lot of the boiler-plate code is concerned with namespaces, which are discussed in this section.

<?xml version="1.0" encoding="utf-8"?>

<ModelDesign
  xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:ua="http://opcfoundation.org/UA/"
  xmlns:FooZbrFlt="https://new.foo.com/zebra-compression/flattening-and-subspacefolding/UA/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  TargetNamespace="https://new.foo.com/zebra-compression/flattening-and-subspacefolding/UA/"
  TargetVersion="0.9.0"
  TargetPublicationDate="2020-05-01T00:00:00Z"
  xmlns="http://opcfoundation.org/UA/ModelDesign.xsd">

  <Namespaces>
    <!--No space allowed at the beginning of the namespace URL!
      Prefix sets the filenames of the generated files. -->
    <Namespace Name="FooZbrFlt" Prefix="FooFlt">https://new.foo.com/zebra-compression/flattening-and-subspacefolding/UA/</Namespace>
    <Namespace Name="OpcUa" Version="1.03" PublicationDate="2013-12-02T00:00:00Z">http://opcfoundation.org/UA/</Namespace>
  </Namespaces>
  
  <!-- ObjectType -->
  <!-- ReferenceType -->
  <!-- VariableType -->
  <!-- DataType -->
  <!-- Object -->
  <!-- Variable -->
  <!-- Property -->
  <!-- Dictionary -->
  <!-- Method -->
  <!-- View -->
  
</ModelDesign>

The XML element ModelDesign has the following attributes:

  • xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd"
    • The link leads to a schema file that defines various complexTypes used by OPCFoundation.
  • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    • required
  • xmlns:ua="http://opcfoundation.org/UA/"
    • Namespace of all OPCFoundation
  • xmlns:FooZbrFlt="https://new.foo.com/zebra-compression/flattening-and-subspacefolding/UA/"
    • this document may use elements of namespace FooZbrFlt. In combination with TargetNamespace this document may define ObjectType elements in that namespace as well as use them from that namespace, as long as their names are correctly prefixed with FooZbrFlt:.
  • xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  • TargetNamespace="https://new.foo.com/zebra-compression/flattening-and-subspacefolding/UA/"
    • this document defines elements in this namespace
  • TargetVersion="0.9.0"
    • optional, used as auxiliary release meta-information
  • TargetPublicationDate="2020-05-01T00:00:00Z"
    • optional, used as auxiliary release meta-information
  • xmlns="http://opcfoundation.org/UA/ModelDesign.xsd"
    • Default namespace of this document

Methods

Define method types explicitly (grey box) and use them via TypeDefinition for method nodes as shown for method MyMethod. Defining methods in-places like MyMethodInPlace will not expose Input- and OutputArguments to the OPC UA client.

Note: In comparison to Object/ObjectType and Variable/VariableType, Method do not have MethodType.

Published inInformation Modeling

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.