The EasyUA CLient SDK includes:
- EasyUA.dll for Windows Forms and Windows Console and Service applications
- EasyUA.WPF.dll for WPF applications
The two DLLs differ only in the BrowseTree and UaDataBind classes, which display server data directly in Forms respectively WPF controls.
The EasyUA DLLs provide a set of classes that handle the OPC UA server communication.
The typical steps for an EasyUA based UA client application are:
- Create a UaClient object
- Load the UA configuration
- Create a session
- Connect to the UA server
The application is now ready to access the server to browse for nodes or to read/write/subscribe nodes with known NodeIds.
Create a UaClient object
The UaClient constructor has one argument that controls the callback handling.
If a Windows Forms or WPF control object is specified the callbacks are synchronized with this object (handler is called thru Invoke).
Sample:
In Windows Forms or WPF applications: uaApp = new UaClient(this);
In Windows Console or Service applications: uaApp = new UaClient(null);
Load the UA configuration
Every application needs to have a UA configurtion file in the executable directory.
The file name is appname.Ua.Config.Xml
The UaClientConfigHelper utility is provided to create/edit the configuration file including the creation/import of certificates.
If it's not necessary to have application specific configuration settings or certificates then the property
UaClient.UaAppConfigFileAutoCreate = "EasyUA Sample";
can be set to have EasyUA create a default configuration and certificate.
To load the configuration file the application must call the method:
uaApp.LoadConfiguration(); // process the UA configuration
Create a Session
The Session can be created in two ways:
- With the UA server discovery URL and a selection for either minimal or maximal security
Sample: session = uaApp.CreateSession("opc.tcp://localhost:62849/Advosol/uaPLUSsim/discovery", false, "test"); - With a specific UA server endpoint
Using server discovery methods the available endpoints can be retrieved from the server. The best suited one can be used>
Sample: session = uaApp.CreateSession( selectedEndpoint, "test");
Connect to the UA server
The application may first install event handlers for notifications and the Connect, either with or without user credentials.
Sample: session.Connect(null);
Sample Applications
C# and VB.NET sample applications are provided for the different kinds of .NET applications:
- Windows Forms
- WPF
- Windows Console Appllication
- Windows Service
The sample code is rather simple but includes important notification and error handling.
The WindowsFormsSample is more complex and uses many EasyUA features with synchronous and asynchronous server calls.