OPC UA Serversshall provide type definitions for Objectsand Variables. The HasTypeDefinition Referenceshall be used to link an instance with its type definition represented by a TypeDefinitionNode. Type definitions are required; however, OPC 10000-5defines a BaseObjectType, a PropertyType,and a BaseDataVariableTypeso a Servercan use such a base type if no more specialised type information is available.Objects andVariables inherit the Attributesspecified by their TypeDefinitionNode (see 6.4for details).
In some cases, the NodeIdused by the HasTypeDefinition Referencewill be well-known to Clientsand Servers. Organizations may define TypeDefinitionNodesthat are well-known in the industry. Well-known NodeIdsof TypeDefinitionNodesprovide for commonality across OPC UA Serversand allow Clientsto interpret the TypeDefinitionNodewithout having to read it from the Server. Therefore, Serversmay use well-known NodeIdswithout representing the corresponding TypeDefinitionNodesin their AddressSpace. However, the TypeDefinitionNodesshall be provided for generic Clients. These TypeDefinitionNodesmay exist in another Server.
The following example, illustrated in Figure 5, describes the use of the HasTypeDefinition Reference. In this example, a setpoint parameter “SP” is represented as a DataVariablein the AddressSpace. This DataVariableis part of an Objectnot shown in the figure.
To provide for a common setpoint definition that can be used by other Objects, a specialised VariableTypeis used. Each setpoint DataVariablethat uses this common definition will have a HasTypeDefinition Referencethatidentifies the common “SetPoint” VariableType.
TypeDefinitionNodescan be complex. A complex TypeDefinitionNodealso defines Referencesto other Nodesas part of the type definition. The ModellingRulesdefined in 6.4.4specify how those Nodesare handled when creating an instance of the type definition.
A TypeDefinitionNodereferences instances instead of other TypeDefinitionNodesto allow unique names for several instances of the same type, to define default values and to add Referencesfor those instances that are specific to this complex TypeDefinitionNodeand not to the TypeDefinitionNodeof the instance. For example, in Figure 6the ObjectType“AI_BLK_TYPE”, representing a function block, has a HasComponent Referenceto a Variable“SP” of the VariableType“SetPoint”. “AI_BLK_TYPE” could have an additional setpoint Variableof the same type using a different name. It could add a Propertyto the Variablethat was not defined by its TypeDefinitionNode“SetPoint”. And it could define a default value for “SP”, that is, each instance of “AI_BLK_TYPE” would have a Variable“SP” initially set to this value.
This approach is commonly used in object-oriented programming languages in which the variables of a class are defined as instances of other classes. When the class is instantiated, each variable is also instantiated, but with the default values (constructor values) defined for the containing class. That is, typically, the constructor for the component class runs first, followed by the constructor for the containing class. The constructor for the containing class may override component values set by the component class.
To distinguish instances used for the type definitions from instances that represent real data, those instances are called InstanceDeclarations. However, this term is used to simplify this specification, if an instance is an InstanceDeclarationor not is only visible in the AddressSpaceby following its References. Some instances may be shared and therefore referenced by TypeDefinitionNodes, InstanceDeclarationsand instances. This is similar to class variables in object-oriented programming languages.
- Clientsthat only know the supertype to handle an instance of the subtype as if it were an instance of the supertype;
- instances of the supertype to be replaced by instances of the subtype;
- specialised types that inherit common characteristics of the base type.
In other words, subtypes reflect the structure defined by their supertype but may add additional characteristics. For example, a vendor may wish to extend a general “TemperatureSensor” VariableTypeby adding a Propertyproviding the next maintenance interval. The vendor would do this by creating a new VariableTypewhich is a TargetNodefor a HasSubtypereference from the original VariableType andadding the new Propertyto it.
The instantiation of complex TypeDefinitionNodesdepends on the ModellingRulesdefined in 6.4.4. However, the intention is that instances of a type definition will reflect the structure defined by the TypeDefinitionNode. Figure 7shows an instance of the TypeDefinitionNode“AI_BLK_TYPE”, where the ModellingRule Mandatory, defined in 18.104.22.168.1, was applied for its containing Variable. Thus, an instance of “AI_BLK_TYPE”, called AI_BLK_1”, has a HasTypeDefinition Referenceto “AI_BLK_TYPE”. It also contains a Variable“SP” having the same BrowseNameas the Variable“SP” used by the TypeDefinitionNodeand thereby reflects the structure defined by the TypeDefinitionNode.
A client knowing the ObjectType“AI_BLK_TYPE” can use this knowledge to directly browse to the containing Nodesfor each instance of this type. This allows programming against the TypeDefinitionNode. For example, a graphical element may be programmed in the client that handles all instances of “AI_BLK_TYPE” in the same way by showing the value of “SP”.
There are several constraints related to programming against the TypeDefinitionNode. A TypeDefinitionNodeor an InstanceDeclarationshall never reference two Nodeshaving the same BrowseNameusing forward hierarchical References. Instances based on InstanceDeclarationsshall always keep the same BrowseNameas the InstanceDeclarationthey are derived from. A special Servicedefined in OPC 10000-4called TranslateBrowsePathsToNodeIds may be used to identify the instances based on the InstanceDeclarations. Using the simple Browse Servicemight not be sufficient since the uniqueness of the BrowseNameis only required for TypeDefinitionNodesand InstanceDeclarations, not for other instances. Thus, “AI_BLK_1” may have another Variablewith the BrowseName“SP”, although this one would not be derived from an InstanceDeclarationof the TypeDefinitionNode.
A TypeDefinitionNodeand its InstanceDeclarationsshall always reside in the same Server. However, instances may point with their HasTypeDefinition Referenceto a TypeDefinitionNodein a different Server.