In this Getting Started, we will create a console application running in .NET 6, 7 or 8 that will read a value from an OPC server, and display the value on the console.
Open a command prompt.
Create a folder named Hello and navigate to the folder.
Type the following: dotnet new console. This command creates a project file (Hello.csproj) and a main program file (Program.cs).
Type the following: dotnet add package OpcLabs.QuickOpc. This command adds QuickOPC package reference to the project file.
Using a text editor, add following code to the beginning of the Program.cs file:
using OpcLabs.EasyOpc.UA;
In Program.cs, replace the body of the Main method by following code:
var client = new EasyUAClient(); object value = client.ReadValue( "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853"); Console.WriteLine(value);
Save the changes to Program.cs.
In the command prompt, type dotnet run. This will build and launch the program. The value will be read from the OPC server and displayed on the console.
Open a command prompt.
Create a folder named HelloXml and navigate to the folder.
Type the following: dotnet new console. This command creates a project file (HelloXml.csproj) and a main program file (Program.cs).
Type the following: dotnet add package OpcLabs.QuickOpc. This command adds QuickOPC package reference to the project file.
Using a text editor, add following code to the beginning of the Program.cs file:
using OpcLabs.EasyOpc.DataAccess;
In Program.cs, replace the body of the Main method by following code:
var client = new EasyDAClient(); object value = client.ReadItemValue( "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double"); Console.WriteLine(value);
Save the changes to Program.cs.
In the command prompt, type dotnet run. This will build and launch the program. The value will be read from the OPC server and displayed on the console.