Visual OPC Server NET Developer Guide
Visual OPC Server NET Developer Guide
Visual OPC Server NET Developer Guide
NET
Develop OPC UA Clients and Servers
with C# / VB.NET
Summary
This document gives a short overview of the functionality of the Visual OPC .NET product family. The goal of this
document is to give an introduction and can be used as base for your own implementations
1 Overview .................................................................................................................................. 8
1.1 OPC Technology ......................................................................................................... 8
1.1.1 Classic OPC Specifications ........................................................................... 8
1.1.2 OPC XML-DA Specification ......................................................................... 8
1.1.3 OPC .NET 3.0 (WCF)................................................................................... 8
1.1.4 OPC Unified Architecture Specification ...................................................... 9
2 Visual OPC .NET Product Line ............................................................................................... 10
2.1 Visual OPC Client .NET ............................................................................................. 10
2.2 Visual OPC Server .NET .............................................................................................11
2.3 Visual OPC Wrapper .NET ........................................................................................ 12
2.4 Visual OPC Proxy .NET ............................................................................................. 13
3 Introduction............................................................................................................................. 14
4 OPC UA Basics ........................................................................................................................ 16
4.1 Specifications ............................................................................................................. 16
4.2 Terms, definitions, and abbreviations ...................................................................... 17
4.2.1 OPC UA terms ............................................................................................. 17
4.2.1.1 AddressSpace ............................................................................... 17
4.2.1.2 Alarm ............................................................................................ 17
4.2.1.3 Attribute ....................................................................................... 17
4.2.1.4 Certificate ..................................................................................... 17
4.2.1.5 Client ............................................................................................ 17
4.2.1.6 Condition ...................................................................................... 17
4.2.1.7 Communication Stack .................................................................. 17
4.2.1.8 Complex Data .............................................................................. 17
4.2.1.9 Discovery ...................................................................................... 18
4.2.1.10 Event ............................................................................................ 18
4.2.1.11 EventNotifier................................................................................ 18
4.2.1.12 Information Model....................................................................... 18
4.2.1.13 Message ....................................................................................... 18
4.2.1.14 Method ......................................................................................... 18
4.2.1.15 MonitoredItem ............................................................................. 18
4.2.1.16 Node ............................................................................................. 18
4.2.1.17 NodeClass .................................................................................... 18
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 3 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 4 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 5 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 6 of 94
Trademark Notice
Microsoft, MSN, Windows and the Windows logo are either registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries. All other trademarks are the property
of their respective owners.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 7 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 8 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 9 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 10 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 11 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 12 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 13 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 14 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 15 of 94
4.1 Specifications
The OPC UA specification is organized as a multi-part specification, splitted into 3 sections:
Unfortunatley most of the OPC UA specification documents can only be downloaded by OPC Foundation
members from the OPC Foundation web site. Only part 1 (Overview and Concepts) is available to the
public. All other parts are available only to OPC Foundation members and may be used only as long as the
user is an active OPC Foundation member.
The OPC Foundation offers an OPC UA SDK but also this one is only available for OPC Foundation
members. Because of this TerxaSoft GmbH decided to develop the Visual OPC Client .NET with the
following main goals:
Ease of Use
By hiding the complexity of the OPC UA specification it should be possible for a developer with
just OPC UA Basic Knowledge to implement an OPC UA client.
Compliance
By using the OPC UA SDK provided by the OPC Foundation as base of the Visual OPC Client .NET
compliance to the OPC UA specification can be guaranteed.
The following sections give the reader an introduction in OPC UA. Most of these parts are summaries of
the OPC UA specifications and are reduced to those parts which are required for the reader to understand
the basics of OPC UA. Mappings between definitions in the OPC UA specifications and those used in the
Visual OPC Client .NET are given as soon as they are used the first time.
In case you are interested in an Overview of OPC UA please consider downloading part 1 (Overview and
Concepts) through the OPC Foundation web site. The direct link is
http://www.opcfoundation.org/DownloadFile.aspx?CM=3&RI=414&CN=KEY&CI=283&CU=7.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 16 of 94
4.2.1.1 AddressSpace
AddressSpace is the collection of information that an OPC UA Server makes visible to its Clients. See Part
3: for a description of the contents and structure of the Server AddressSpace.
4.2.1.2 Alarm
A type of Event associated with a state condition that typically requires acknowledgement. See Part 9: for
a description of Alarms.
4.2.1.3 Attribute
An Attribute is a primitive characteristic of a Node. All Attributes are defined by OPC UA, and may not be
defined by Clients or Servers. Attributes are the only elements in the AddressSpace permitted to have data
values.
4.2.1.4 Certificate
A certificate is a digitally signed data structure that describes capabilities of a Client or Server.
4.2.1.5 Client
A software application that sends Messages to OPC UA Servers conforming to the Services specified in
this set of specifications.
4.2.1.6 Condition
A Condition is a generic term that is an extension to an Event. A Condition represents the conditions of a
system or one of its components and always exists in some state.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 17 of 94
4.2.1.10 Event
A generic term used to describe an occurrence of some significance within a system or system component.
4.2.1.11 EventNotifier
A special Attribute of a Node that signifies that a Client may subscribe to that particular Node to receive
Notifications of Event occurrences.
4.2.1.13 Message
The data unit conveyed between Client and Server that represents a specific Service request or response.
4.2.1.14 Method
A Method is a callable software function that is a component of an Object.
4.2.1.15 MonitoredItem
A Client-defined entity in the Server used to monitor Attributes or EventNotifiers for new values or Event
occurrences and generate Notifications for them.
4.2.1.16 Node
A Node is the fundamental component of an AddressSpace.
4.2.1.17 NodeClass
A NodeClass is the class of a Node in an AddressSpace. NodeClasses define the metadata for the
components of the OPC UA Object Model. They also define constructs, such as Views, that are used to
organize the AddressSpace.
4.2.1.18 Notification
The generic term for data that announces the detection of an Event or of a changed Attribute value.
Notifications are sent in NotificationMessages.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 18 of 94
4.2.1.20 Object
An Object is a Node that represents a physical or abstract element of a system. Objects are modelled using
the OPC UA Object Model. Systems, subsystems and devices are examples of Objects. An Object may be
defined as an instance of an ObjectType.
4.2.1.22 ObjectType
An ObjectType is a Node that represents the type definition for an Object.
4.2.1.23 Profile
A specific set of capabilities, defined in Part 7:, to which a Server may claim conformance. Each Server
may claim conformance to more than one Profile.
4.2.1.24 Program
An executable Object that, when invoked, immediately returns a response to indicate that execution has
started, and then returns intermediate and final results through Subscriptions identified by the Client
during invocation.
4.2.1.25 Reference
A Reference is an explicit relationship (a named pointer) from one Node to another. The Node that
contains the Reference is the source Node, and the referenced Node is the target Node. All References are
defined by ReferenceTypes.
4.2.1.26 ReferenceType
A ReferenceType is a Node that represents the type definition of a Reference. The ReferenceType specifies
the semantics of a Reference. The name of a ReferenceType identifies how source Nodes are related to
target Nodes and generally reflects an operation between the two, such as “A Contains B”.
4.2.1.27 RootNode
The beginning or top Node of a hierarchy. The RootNode of the OPC UA AddressSpace is defined in Part
5.
4.2.1.28 Server
A software application that implements and exposes the Services specified in this set of specifications.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 19 of 94
4.2.1.31 Session
A Session is a logical long-running connection between a Client and a Server. A Session maintains state
information between Service calls from the Client to the Server.
4.2.1.32 Subscription
A Client-defined endpoint in the Server, used to return Notifications to the Client. Generic term that
describes a set of Nodes selected by the Client (1) that the Server periodically monitors for the existence
of some condition, and (2) for which the Server sends Notifications to the Client when the condition is
detected.
4.2.1.33 Variable
A Variable is a Node that contains a value.
4.2.1.34 View
A View is a specific subset of the AddressSpace that is of interest to the Client.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 20 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 21 of 94
Object
Data Change
Notification
Variables
……..
…….. References to
Read/Write …….. other objects
Invoke
Methods
……..()
Event
Notification
……..()
……..()
The elements of this model are represented in the AddressSpace as Nodes. Each Node is assigned to a
NodeClass and each NodeClass represents a different element of the Object Model.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 22 of 94
Node
Attributes Attributes describe a Node
……..
……..
……..
References define
relationships to other nodes
References
……..
……..
……..
Node
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 23 of 94
4.3.2.3 References
References are used to relate Nodes to each other. They can be accessed using the browsing and querying
Services.
Like Attributes, they are defined as fundamental components of Nodes. Unlike Attributes, References are
defined as instances of ReferenceType Nodes. ReferenceType Nodes are visible in the AddressSpace and
are defined using the ReferenceType NodeClass.
The Node that contains the Reference is referred to as the SourceNode and the Node that is referenced is
referred to as the TargetNode. The combination of the SourceNode, the ReferenceType and the
TargetNode are used in OPC UA Services to uniquely identify References.
Thus, each Node can reference another Node with the same ReferenceType only once. Any subtypes of
concrete ReferenceTypes are considered to be equal to the base concrete ReferenceTypes when
identifying References). The following figure illustrates this model of a Reference.
SourceNode
ReferenceName TargetNode
The TargetNode of a Reference may be in the same AddressSpace or in the AddressSpace of another OPC
UA server. TargetNodes located in other servers are identified in OPC UA Services using a combination of
the remote server name and the identifier assigned to the Node by the remote server.
OPC UA does not require that the TargetNode exists, thus References may point to a Node that does not
exist.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 24 of 94
4.3.3.1 Properties
Properties are server-defined characteristics of Objects, DataVariables and other Nodes. Properties differ
from Attributes in that they characterise what the Node represents, such as a device or a purchase order.
Attributes define additional metadata that is instantiated for all Nodes from a NodeClass. Attributes are
common to all Nodes of a NodeClass and only defined by this specification whereas Properties can be
server-defined.
For example, an Attribute defines the DataType of Variables whereas a Property can be used to specify the
engineering unit of some Variables.
To prevent recursion, Properties are not allowed to have Properties defined for them. To easily identify
Properties, the BrowseName of a Property shall be unique in the context of the Node containing the
Properties.
A Node and its Properties shall always reside in the same server.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 25 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 26 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 27 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 28 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 29 of 94
The Binding may be passed directly to the Channel objects (See WCF Channels and Clients) when they are
created, however, the OPC UA Core Stack also provides a BindingFactory mechanism that allows the
Channel to create the correct Binding from the current configuration information. Developers should
initialize the BindingFactory from the application configuration and then pass the BindingFactory to the
Channel object. The Channel object will then create the Binding that matches the scheme in the URL for
the endpoint.
Administrators can then specify the mapping between different URL schemes and .NET classes in the
application configuration file (See Application Configuration).
This mechanism allows new WCF Bindings and protocols to be added to applications after they have been
deployed, however, it does not offer the ability to construct an arbitrary WCF Binding in a configuration
file. This capability was intentionally left out because minor differences in WCF Bindings can create
interoperability problems when applications developed by multiple vendors are deployed in a production
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 30 of 94
Developers can create new Bindings creating subtypes of the BaseBinding class. The subtypes must define
a constructor with the parameters described in the table below.
Name Type Description
namespaceUris NamespaceTable A reference to the Server’s namespace table.
factory EncodeableFactory A reference to a factory capability of
encoding/decoding extensible parameters and
structured data values
configuration EndpointConfiguration The configuration for Endpoint.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 31 of 94
The EndpointConfiguration is used by custom Bindings to initialize the WCF Channel objects.
Servers create their EndpointDescription and EndpointConfigurations from the configuration provided by
the Administrator. Clients can retrieve the EndpointDescriptions for different Servers using the Discovery
Services, however, they may also be provided by the Administrator and/or User. The Client’s
EndpointConfiguration are always specified by the Administrator and/or User.
5.4.5 ConfiguredEndpoints
Client applications frequently need to persist information that will allow them to reconnect to a Server.
This information includes the EndpointDescription and EndpointConfiguration, however, it could include
other information such as the username/password. The ConfiguredEndpoint and
ConfiguredEndpointCollection classes allow Clients to persist this kind information. They also provide
convenience functions that assist with updating the information using the Discovery Services.
The ConfiguredEndpoint defines an Extensions property which allows application developers to save their
own configuration information with the endpoint.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 32 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 33 of 94
XML
<configSections>
<section name="DataAccessConsole" type="Opc.Ua.ApplicationConfigurationSection,Opc.Ua.Core"/>
</configSections>
The name may be any text that is unique within the app.config file. The ConfigurationLocation would look
like this XML fragment:
XML
<DataAccessConsole>
<ConfigurationLocation xmlns="http://opcfoundation.org/UA/SDK/Configuration.xsd">
<FilePath>DataAccessConsole.Config.xml</FilePath>
</ConfigurationLocation>
</DataAccessConsole>
The FilePath can be an absolute path or a relative path. If it is a relative path the current directory is
searched followed by the directory where the executable resides. The stack also supports prefixes which
can be replaced with environment variables. The latter functionality requires a token enclosed by ‘%’
symbols at the start of the message. The stack will first check for a symbol that matches one of the values
from the Environment.SpecialFolder enumeration. If not found it will use the environment variable of the
same name.
Note that the same feature exists for all fields that represent file directory paths in the
ApplicationConfiguration object.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 34 of 94
XML
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 35 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 36 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 37 of 94
XML
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 38 of 94
The NodeId, ExpandedNodeId, QualifiedName and LocalizedText classes cannot be modified after
construction. This means they can be safely passed around as references without risk of side effects. These
types also define a static property called Null which should be used instead of the default constructor.
The stack provides an enumeration called BuiltInType that can be used to set up switch statements. The
numeric value for each BuiltInType is the same as the NodeId for the corresponding DataType Node.
The stack also provides a helper class called TypeInfo which provides methods to detect the Built-in Type
for an object and to convert between types.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 39 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 40 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 41 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 42 of 94
5.5.2.1 Namespaces
This element defines the mappings between the URIs used to identify namespaces and the symbols used
in code. It is possible that a user defined design file includes other user defined design files. This allows
the user to split larger models into several files. The location of included design files is specified with the
FilePath attribute (absolute or relative path without the .xml suffix).
Namespace sample
<opc:Namespaces>
<opc:Namespace Name="OpcUa" Prefix="Opc.Ua"
XmlNamespace="http://opcfoundation.org/UA/2008/02/Types.xsd">http://opcfoundation.org/UA/</opc:Namespace>
<opc:Namespace Name="Boiler" Prefix="Boiler">http://terxasoft.ch/Boiler</opc:Namespace>
</opc:Namespaces>
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 43 of 94
ObjectType sample
5.5.2.3 Object
An Object is a Node that represents a physical or abstract element of a system. Objects are modelled using
the OPC UA Object Model. Systems, subsystems and devices are examples of Objects. An Object may be
defined as an instance of an ObjectType.
Normally instances are created by program logic instead of being part of the model. This is provided as an
example of how to do it when there is a need for persistent instances. Note that the DisplayNames are
overridden for the base level nodes.
Object sample
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 44 of 94
VariableType sample
5.5.2.5 Variable
Variable sample
5.5.2.6 ReferenceType
ReferenceType sample
5.5.2.7 DataType
DataType sample
5.5.2.8 Properties
Properties sample
<opc:Property SymbolicName="SetPoint"/>
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 45 of 94
BuildDesign.bat sample
@echo off
setlocal
SET PATH=%PATH%;..\..\..\..\Scripts;..\..\..\..\Binaries;..\..\..\Binaries
Execute the batch file and for the BoilerServer sample the following files should be created:
Boiler.Classes.cs
Boiler.Constants.cs
Boiler.DataTypes.cs
Boiler.PredefinedNodes.uanodes
ModelDesign.csv (only if it not already exists)
In addition also some more files are created but not used at the moment.
3. Add the files to your server project
1. Add the C# files Boiler.Classes.cs, Boiler.Constants.cs and Boiler.DataTypes.cs to your project.
2. Add the UANODES file Boiler.PredefinedNodes.uanodes as Embedded resource to your
project.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 46 of 94
OnGetNamespaceUris() method
/// <summary>
/// Defines namespaces used by the application.
/// </summary>
/// <returns>Array of namespaces that are used by the application.</returns>
public string[] OnGetNamespaceUris()
{
// set one namespace for the type model.
var namespaceUrls = new string[2];
namespaceUrls[0] = Boiler.Namespaces.Boiler;
namespaceUrls[1] = Boiler.Namespaces.Boiler + "/Instance";
return namespaceUrls;
}
OnCreateAddressSpace() method
/// <summary>
/// <para>
/// This method is called from the generic server at the startup; when the first client connects
/// or the service is started. All items supported by the server need to be defined by calling
/// the methods provided by the <see cref="IOpcServer">IOpcServer</see> interface for each item.
/// </para>
/// </summary>
/// <param name="opcServer">The generic server object. Used to call methods the generic server
/// provides.</param>
/// <param name="externalReferences">The externalReferences allows the generic server to link to the
/// general nodes.</param>
/// <returns>The root folder.</returns>
public object OnCreateAddressSpace(IOpcServer opcServer, IDictionary<NodeId, IList<IReference>>
externalReferences)
{
opcServer_ = opcServer;
opcServer_.LoadPredefinedNodes("UaServerPlugin.Boiler.PredefinedNodes.uanodes", externalReferences);
#region Create objects based on the classes generated by the model compiler
// See next step
#endregion
// the root node was created by calling the LoadPredefinedNodes() method and therefore we
// return null here.
return null;
The LoadPredefinedNodes() method uses the resource name of the embedded resource which
consists of UaServerPlugin plus the UANODES file name (without extension).
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 47 of 94
#region Create objects based on the classes generated by the model compiler
// find the untyped Boiler1 node that was created when the model was loaded.
var passiveNode = (BaseObjectState)opcServer_.FindPredefinedNode(new NodeId(Boiler.Objects.Boiler1,
opcServer_.NamespaceIndexes[0]), typeof(BaseObjectState));
// convert the untyped node to a typed node that can be manipulated within the server.
boiler1_ = new BoilerState(null);
boiler1_.Create(opcServer_.SystemContext, passiveNode);
// replaces the untyped predefined nodes with their strongly typed versions.
opcServer_.AddPredefinedNode(boiler1_);
// initialize it from the type model and assign unique node ids.
boiler2_.Create(
opcServer_.SystemContext,
null,
new QualifiedName("Boiler #2", opcServer_.NamespaceIndexes[1]),
null,
true);
// store it and all of its children in the pre-defined nodes dictionary for easy look up.
opcServer_.AddPredefinedNode(boiler2_);
#endregion
Check also the DoSimulation() method to see how the created objects are used to modify
values during runtime.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 48 of 94
6.1 Classes
6.1.1 ApplicationInstance
The ApplicationInstance class is a class that install,
configures and runs a UA client application. It is the
first object which must be created.
Loading ApplicationConfiguration CS
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 49 of 94
6.1.1.2 Methods
The ApplicationInstance class has the following methods:
CheckCertificate This method checks for a valid application instance certificate. This
method throws a ServiceResultException if an error occurs.
Note:
In case a problem with the certificate occurs the
CertificateUpdateEventHandler will be called if used.
LoadConfiguration This method checks for a valid application instance certificate.
This method throws a ServiceResultException if an error occurs. This
method has the following parameters:
Name Description
configSectionName The name of the config section
containing the path to the application
configuration file.
[Return Value] True if the arguments were processed;
False otherwise.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 50 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 51 of 94
Remote servers can be discovered by specifiying an Uri object like shown below:
6.1.2.1 Properties
The Discover class has the following properties:
Name Description
DiscoveryTimeout The timeout in milliseconds to use when discovering servers.
6.1.2.2 Methods
The Discover class has the following methods:
GetConfiguredEndpoint Returns the configured endpoint for a given endpoint description.
Name Description
endpointDescription The endpoint description as
EndpointDescription.
[Return Value] The configured endpoint as
ConfiguredEndpoint.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 52 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 53 of 94
6.1.3.1 Overview
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 54 of 94
6.1.3.1.2 Keepalive
After creating the session the Session object starts periodically reading the current state from the Server at
a rate specified by the KeepAliveInterval (default is 5s). Each time a response is received the state and
latest timestamp is reported as a KeepAlive event. If the response does not arrive after 2
KeepAliveIntervals have elapsed a KeepAlive event with an error is raised. The KeepAliveStopped property
will be set to true. If communication resumes the normal KeepAlive events will be reported and the
KeepAliveStopped property will go back to false.
The client application uses the KeepAlive event and KeepAliveStopped property to detect communication
problems with the server. In some cases these communication problems will be temporary but while they
are going on the client application may choose not to invoke any services because they would likely
timeout. If the channel does not come back on its own the client application will execute whatever error
recovery logic it has.
Client applications need to ensure that the SessionTimeout is not set too low. If a call times out the WCF
channel is closed automatically and the client application will need to create a new one. Creating a new
channel will take time. The KeepAliveStopped property allows applications to detect failures even if they
are using a long SessionTimeout.
6.1.3.1.3 Cache
The Session object provides a cache that can be used to store Nodes that are accessed frequently. The
cache is particularly useful for storing the types defined by the server because the client will often need to
check if one type is a subtype of another. The cache can be accessed via the NodeCache property of the
Session object. The type hierarchies stored in the cache can be searched using the TypeTree property of
the NodeCache or Session object (the both return a reference to the same object).
The NodeCache is populated with the FetchNode() method which will read all of the attributes for the
Node and the fetch all of its references. The Find() method on the NodeCache looks for a previously
cached version of the Node and calls the FetchNode() method if it does not exist.
Client applications that wish to use the NodeCache must pre-fetch all the ReferenceType hierarchy
supported by the Server by calling FetchTypeTree() method on the Session object.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 55 of 94
6.1.3.1.5 Multi-Threading
The Session is designed for multi-threaded operation because client application frequently needs to make
multiple simultaneous calls to the Server. However, this is only guaranteed for calls using the Session
class. Client applications should avoid calling services directly which update the Session state, e.g.
CreateSession or ActivateSession.
6.1.3.2 Events
6.1.3.2.1 RenewUserIdentityEvent
The RenewUserIdentityEvent occurs before a reconnect
operation completes and is called to refresh the identity
(reprompt for password, refresh token). Within the event
handler the property Identity of the session object can be
updated before return.
The RenewUserIdentityEventArgs has the following properties:
Name Description
Identity The user identity which should be refreshed.
The following example shows the usage of the RenewUserIdentityEvent:
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 56 of 94
6.1.3.2.2 SessionClosingEvent
The SessionClosingEvent occurs to indicate that the session is closing. The following example shows the
usage of the SessionClosingEvent:
6.1.3.2.3 SessionKeepAliveEvent
The SessionKeepAliveEvent is raised when a keepalive arrives
from the server or an error is detected.
The SessionKeepAliveEventArgs has the following properties:
Name Description
CancelKeepAlive Gets or sets a flag indicating whether the session should send another
keepalive.
CurrentState The current server state.
CurrentTime The current server time.
Status The status associated with the keepalive operation.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 57 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 58 of 94
Name Description
NotificationMessage The Notification Message as NotificationMessage object.
StringTable The string table as IList<string> returned with the notification
message.
Subscription The subscription as Subscription object that the notification applies to.
mySession.SessionNotificationEvent += new
EventHandler<SessionNotificationEventArgs>(OnSessionNotification);
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 59 of 94
Name Description
SequenceNumber The sequence number for the message that could not be republished.
Status The status as ServiceResult object associated with the keepalive
operation.
SubscriptionId The subscription with the message that could not be republished.
mySession.SessionPublishErrorEvent += new
EventHandler<SessionPublishErrorEventArgs>(OnSessionPublishError);
6.1.3.2.6 SubscriptionsChangedEvent
Raised when a subscription is added or removed.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 60 of 94
Using a Subscription CS
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 61 of 94
When a Subscription is created it must start sending Publish requests. It starts off the process by telling
the Session object to send one request. Additional Publish requests can be send by calling the
BeginPublish() method. Applications can use additional Publish requests to compensate for high network
latencies because once the pipeline is filled the Server will be able to return a steady stream of
notifications.
Once the Subscription has primed the pump the Session object keeps it going by sending a new Publish
whenever it receives a successful response. If an error occurs the Session raises a SessionPublishError
event and does not send another Publish.
If everything is working properly the Session saves the message in cache at least once per keepalive
interval. If a NotificationMessage does not arrive it means there are network problems, bugs in the Server
or high priority Subscriptions are taking precedence. The keepalive timer is designed to detect these
problems and to automatically send additional Publish requests. When the keepalive timer expires it
checks the time elapsed since the last notification message. If publishing appears to have stopped the
PublishingStopped property will be true and the Subscription will raise a PublishStatusChanged event and
send another Publish request. Client applications must assume that any cache data values are out of date
when they receive the PublishStatusChanged event (e.g. the StatusCode should be set to
UncertainLastKnownValue). However, client applications do not need to do anything else since the
interruption may be temporary. It is up to the client application to decide when to give up on a Session
and to try again with a new Session.
The Subscription object checks for missing sequence numbers when it receives a NotificationMessage. If
there is a gap it starts a timer that will call Republish() in 1s if the gap still exists. This delay is necessary
because the multi-threaded stack on the client side may process responses out of order even if they are
received in order.
The Subscription maintains a cache of messages received. The size of this cache is controlled by the
MaxMessageCount property. When a new message is received the Subscription adds it to the cache and
removes any extras. It then extracts the notifications and pushes them to the MonitoredItem identified by
the ClientHandle in the notification.
The Subscription is designed for multi-threaded operation because the Publish requests may arrive on any
thread. However, data which is accessed while processing an incoming message is protected with a
separate synchronization lock from data that is used while updating the Subscription parameters. This
means notifications can continue to arrive while network operations to update the Subscription state on
the server are in progress. However, no more than one operation to update the Subscription state can
proceed at one time. Closing the Session will interrupt any outstanding operations. Any synchronization
locks held by the subscription are released before any events are raised.
6.1.4.2 Events
6.1.4.2.1 PublishStatusChangedEvent
Raised to indicate the publishing state for the subscription has stopped or resumed (see
PublishingStopped property).
The following example shows the usage of the PublishStatusChangedEvent:
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 62 of 94
/// <summary>Called when the publishing state for a subscription has stopped or resumed</summary>
/// <param name="sender">Source of the event as Subscription object.</param>
/// <param name="eventArgs">Event information to send to registered event handlers.</param>
private void OnPublishStatusChanged(object sender, EventArgs eventArgs)
{
return;
}
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 63 of 94
Name Description
Status The changes as SubscriptionChangeMask object that have affected the
subscription.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 64 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 65 of 94
6.1.5.1 Events
6.1.5.1.1 MonitoredItemNotificationEvent
Raised when a new notification arrives.
The MonitoredItemNotificationEventArgs has the
following properties:
Name Description
NotificationValue The new notification as IEncodable.
mySession.MonitoredItemNotificationEvent += new
EventHandler<MonitoredItemNotificationEventArgs>(OnMonitoredItemNotificationEvent);
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 66 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 67 of 94
IOpcBaseDataVariableState BaseDataVariableState
IOpcFolderState FolderState
OpcBuiltInType BuiltInType
OpcValueRanks ValueRanks
OpcAccessLevels AccessLevels
OpcStatusCodes StatusCodes
OpcServerState ServerState
OpcServerProperties ServerProperties
OpcRange Range
OpcReferenceTypes ReferenceTypes
Identifier NodeId
IOpcEndpoint EndpointDescription
Url.ToString() (of Endpoint) EndpointUrl
IOpcSession Session
IOpcSubscription Subscription
SessionName (of Session) SessionDiagnostics.SessionName
ClientLastContactTime (of Session) SessionDiagnostics.ClientLastContactTime
ListViewItem(subscription.Id) ListViewItem(subscription.Id.ToString())
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 68 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 69 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 70 of 94
7.2.1.1 Methods
The IOpcServerPlugin interface has the following methods:
Name Description
OnStartup This method is the first method called from the generic server at the
startup.
This method has the following parameters:
Name Description
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 71 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 72 of 94
The following rules apply for updating the cache base on the returned
StatusCode:
1. If the returned value is Bad (something like Bad...) the cache is
not updated with timestamp and value.
2. If the returned value is GoodCompletesAsynchronously the
cache is not updated with timestamp and value. After the
customization DLL has finished its operation it can use
WriteVariable to update the cache.
3. In all other cases the cache is updated with timestamp and
value.
4. In all cases the status code is updated with the status code set
in the 'statusCode' parameter.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 73 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 74 of 94
7.2.2.1 Properties
The IOpcServer interface has the following properties:
Name Description
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 75 of 94
• uint
• Guid
• string
• byte[]
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 76 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 77 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 78 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 79 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 80 of 94
• uint
• Guid
• string
• byte[]
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 81 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 82 of 94
• uint
• Guid
• string
• byte[]
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 83 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 84 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 85 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 86 of 94
• uint
• Guid
• string
• byte[]
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 87 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 88 of 94
Please see also the provided solutions of the original “VisualOpc40.Server.exe” and ensure that you use
the one for the .NET Framework version you develop for.
In case you have any questions please feel free to contact us.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 89 of 94
8.1 Classes
8.1.1 LicenseHandler
The LicenseHandler class is a class used to license the
Visual OPC Client .NET has product. It should be used
before any other class is used.
After purchaseing the Visual OPC Client .NET you will
receive an email with the information required to be used as
parameters for the Validate method of the LicenseHandler
class. The call looks then like:
License as product CS
8.1.1.1 Properties
The LicenseHandler class has the following properties:
Name Description
DaysLeft Returns the number of days left for the evaluation of the product.
In case of a licensed product this property gives the number of days left for
updateing.
• Products relesased within this time can be used as licensed version.
• Products released after this time can only be used as evaluation.
IsLicensed Returns wether the product is licensed or used as evaluation version.
LicensedAt Returns the information the license was issued or the first date the
evaluation was started.
LicensedAt Returns the Licensee information.
ProductInformation Returns the product information.
ServiceExpired Indicates wether the service subscription or evaluation period is expired.
Version Returns the Version of the product.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 90 of 94
Name Description
Validate Validate the license.
This method has the following parameters:
Name Description
licenseOwner The owner of the license.
licenseKey The license key.
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 91 of 94
Maintenance Package …
A Maintenance Package includes one year of upgrades to all new releases and fixes of the product, and
email based support. All product licenses include a Maintenance Package for the first year. Support
Incidents can be used and transferred as long as a valid Maintenance Package is available. You are
recommended to re-order a Maintenance Package before expiry date. If you re-order Maintenance
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 92 of 94
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 93 of 94
Continuous progress
Lifelong learning and continuing education is, especially in the information technology, essential
for future success. Concerning our customers, we will constantly accepting new challenges and
exceeding their requirements again and again. We will continue to do everything to fulfill the
needs of our customers and to meet our own standards.
TerxaSoft GmbH
Windleweg 3
CH-5235 Rüfenach
Tel.: +41 56 535 16 33
[email protected]
www.terxasoft.ch
Visual OPC Client&Server .NET Developer Guide - Version 1.0 - 29/04/12 Page 94 of 94