If you are interested in OPC Data Client.NET, your task will most certainly involve reading data from an OPC server. Here are a few steps that illustrate how to achieve that, using Microsoft Visual Studio, and a simple Windows Forms application in C#. The steps are quite similar if you are using other tools or a different programming language.
We will create a form that will read a float value from the OPC server when loaded, and immediately display the formatted value in the text box on the form.
Install OPC Data Client. Make sure that you have selected an installation choice that includes .NET development.
Start Microsoft Visual Studio, and create new Visual C# or Visual Basic project, selecting “Windows Forms App (.NET Framework)” template. Make sure that in the lower part of the “New Configure your new project” dialog, the framework is set to “.NET Framework 4.7.2” or later.
Instantiate the EasyDAClient component in the form: Drag the EasyDAClient component from the “QuickOPC Components” tab of the Toolbox to the form’s design surface.
An icon labeled “easyDAClient1” will appear below the form.
If the needed components do not show in the Toolbox: See Troubleshooting the Visual Studio Extension.
Note: This is just shortcut way in Windows Forms to declaring and instantiating the component. In other environments, you can instantiate the component using the ‘new’ (C#) or ‘New’ (VB.NET) keyword, or any other way provided by the language or tool you are using.
Add a textbox to the form: Drag the TextBox component from the Toolbox to the form’s design surface. The text box should appear on the form, and in the Properties window, you will see that it has been given a “textBox1” name.
Add handler for the Load event of the form: Select the form by clicking on its design surface. Then, in the Properties window, choose the “Events” view (orange lightning icon), and double-click the line with “Load” event (it is under Behavior group). A “Form1_Load” text in bold font will appear next to the event name, and a new event handler will be created for the Load event. The text editor will open for the code, and the caret will be placed into the Form1_Load method.
Add following code to the beginning of the Form1.cs file:
using OpcLabs.EasyOpc.DataAccess;
Write the event handler implementation. Add the following code to the body of Form1_Load method:
textBox1.Text = easyDAClient1.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Single").ToString();
Build the project.
Run the application and observe the results. The text box on the form will be filled with a float value we have read from the OPC server, using a single code line!
We will create a form that will read a float value from the OPC server when loaded, and immediately display the formatted value in the text box on the form.
Install OPC Data Client. Make sure that you have selected an installation choice that includes .NET development.
Start Microsoft Visual Studio, and create new Visual C# or Visual Basic project, selecting “Windows Forms App (.NET Framework)” template. Make sure that in the lower part of the “New Configure your new project” dialog, the framework is set to “.NET Framework 4.7.2” or later.
Instantiate the EasyDAClient component in the form: Drag the EasyDAClient component from the “QuickOPC Components” tab of the Toolbox to the form’s design surface.
An icon labeled “easyDAClient1” will appear below the form.
If the needed components do not show in the Toolbox: See Troubleshooting the Visual Studio Extension.
Note: This is just shortcut way in Windows Forms to declaring and instantiating the component. In other environments, you can instantiate the component using the ‘new’ (C#) or ‘New’ (VB.NET) keyword, or any other way provided by the language or tool you are using.
Add a textbox to the form: Drag the TextBox component from the Toolbox to the form’s design surface. The text box should appear on the form, and in the Properties window, you will see that it has been given a “textBox1” name.
Add handler for the Load event of the form: Select the form by clicking on its design surface. Then, in the Properties window, choose the “Events” view (orange lightning icon), and double-click the line with “Load” event (it is under Behavior group). A “Form1_Load” text in bold font will appear next to the event name, and a new event handler will be created for the Load event. The text editor will open for the code, and the caret will be placed into the Form1_Load method.
Add following code to the beginning of the Form1.cs file:
using OpcLabs.EasyOpc.DataAccess;
Write the event handler implementation. Add the following code to the body of Form1_Load method:
textBox1.Text = easyDAClient1.ReadItemValue( "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double").ToString();
Build the project.
Run the application and observe the results. The text box on the form will be filled with a float value we have read from the OPC server, using a single statement!
If you are targeting an environment different from Windows Forms (such as console application, Web, or WPF), your steps will be similar. Instead of dragging the EasyDAClient component from the Toolbox, simply reference the OpcLabs.EasyOpcClassic assembly, and create a new instance of OpcLabs.EasyOpc.DataAccess.EasyDAClient object.
In runtime, all user interface features (such as controls, dialogs, and live binding; Windows Forms and WPF) and nonvisual components are supported both under .NET Framework and .NET 6+. However, "designing" them (this includes tasks like dragging from the Toolbox, or configuring in Properties window) in Visual Studio is only possible in .NET Framework projects. In order to achieve visual design for .NET 6+ projects, the developer can make two project files over the same set of source files, one targeting .NET Framework and one targeting .NET 6+, and use the project that targets .NET Framework for visual design tasks. |