OPCDA.NET Reference Manual
How To Use OPCDA.NET
Send comments on this topic.
OPCDA.NET Client Component > Getting Started > How To Use OPCDA.NET

Glossary Item Box

OPCDA.NET is added to a client application Visual Studio project by adding a reference to the OpcDaNet.dll file. This can be done manually or by using the Add OPCDA.NET Class Wizard or the New OPCDA.NET Project Wizard.

The easiest way to create a OPC client application is by using the invisible DAServer/DAgroup controls provided by the OCPDA.NET Professional Edition. Coding requirements are greatly reduced. Much of the configuration is done in the Visual Studio Designer and high quality server access handling is encapsulated in the controls.


OPCDA.NET has a layered structure and the application can use the methods in all layers to either achieve highest performance or ease of use.

In addition to the layered structure within OPCDA.NET the Professional Edition offers the possibility to add the OPCDA.NET-UA option to add support for accessing OPC UA servers.

 

Base Layer

The classes OpcServer and OpcGroup contain methods for each server function defined in the OPC DA V2 and V3 specification.

 

QuickUse classes

The SyncIOGroup and RefreshGroup class offers simplified item access by name. The OPC group handling is done within the SyncIOGroup.

The BrowseTree class browses the server branch/time structure in one call.

The ShowBrowseTree and ShowBrowseTreeList browse the server and display the branch structure in Windows dialogs.

The ItemListLoader class loads OPCItemDef objects from XML files and simplifies clients that use a predefined set of items.

The OpcServerBrowser class browses the OPC servers on the local or a remote computer.

 

DataBind

The OpcDataBind class bases on the RefreshGroup class and simplifies the OPC server access even further. DataBind subscriptions refresh item values in user objects and Windows dialogs without need for any user callback handler code. The Subscribe method links the OPC server item to a property in the user or Windows dialog object. The object is updated whenever the OPC server makes a callback with a new item value.

 

OPC DA V3 Emulation

The OPCDA.NET Professional Edition emulates some OPC DA V3 features for OPC DA V2 servers. The client application can use these features without knowing the server type. If actually an OPC DA V3 server is accessed then the appropriate server method is called, otherwise OPCDA.NET emulates the function by using available OPC DA V2 features.
Supported features are:
- Browse
- GetProperties
- KeepAlive callbacks (SetKeepAlive must be executed for each group to activate KeepAlive callbacks)

Some servers implement the OPC DA V3 interfaces but not the actual methods. In this case the application needs to set the OpcServer.DeclareV2 property to force the emulation to be used.

 

Background Server Access

The BackGround Server Access classes handle the server access in background threads to prevent the application from becoming unresponsive due to long server processing times or long timeouts in case of DCOM communication failures. The Invoke handling explained above is handled internally in the BGAccess classes. High quality client applications with extensive server access error checking can be built with little user code.
These classes are only available in the OPCDA.NET Professional Edition.

 

Visual Studio Designer Components for Server/Group Handling

The DAServer/DAGroup controls encapsulate most of the code necessary for high quality OPC server access. The user code is minimized and simplified.

 

 

Clients with dynamic/static set of items

Some client application access OPC server items based on user dialog, other work with a predefined set of items.

Clients with item selection by the user The browse methods show the OPC server items in Windows dialogs and allow the user to select the items that have to be accessed. The server tree structure can be displayed in a TreeView control. These controls allow only the selection of a single node. If an application needs to allow the selection of multiple items then the ShowBrowseTreeList class can be used. It displays the branches in a TreeView control and the items of the selected branch in a ListView control. ListView dialogs allow the selection of multiple nodes.
Clients with predefined items Application that use a predefined set of items can define the item IDs in the code or read them from a configuration file. A test client can be used to find the correct item IDs.
The ItemListBuilder application can be used to browse the the OPC server and write the selected items into an XML file. The ItemListLoader class loads such XML files and build OPCItemDef array objects as they are used in the AddItems method. The XML file can be embedded into the application EXE to hide it and to prevent modification. It can alternatively kept as a separate file to allow item set changes without having to recompile the application.
In the DAGroup Control the items can be selected in the Design phase. Additionally item sets for use in read/write calls can be defined.

 

 

Multi-threading

The OPCDA.NET classes can be used in multiple threads to access a single or multiple OPC servers.

Asynchronous server call involve multiple threads even if the application defines only one thread. Callback from the server are handled in separate threads. If the callback handler access Windows Forms or WPF controls then the threads have to be coordinated by having the following code at the begin of the callback handler:

VB.Net

 

If InvokeRequired Then
      BeginInvoke(New DataChangeEventHandler(AddressOf OpcGrp_DataChanged), New Object() {sender, e})
      Return
End If

C#

 

if( InvokeRequired )
{
      BeginInvoke( new DataChangeEventHandler(OpcGrp_DataChanged), new object[] { sender, e } );
     return;
}

The Background server access classes and the DAServer/DAGroup controls handle the multi-threading synchronization internally.

Copyright © 2002-2018 Advosol Inc. All Rights Reserved.