OPC Studio User's Guide and Reference
Getting Started with OPC Data Client under .NET 6+ using .NET CLI Tools
Getting Started > Getting Started with OPC Data Client > Getting Started with OPC Data Client under .NET Framework or .NET > Getting Started with OPC Data Client under .NET 6+ using .NET CLI Tools
In This Topic

In this Getting Started, we will create a console application running in .NET 6 or 8 that will read a value from an OPC server, and display the value on the console.

Prerequisites

If you want to verify the version of .NET on your computer, use the dotnet --info command in the command prompt, and look for the Version field under ".NET runtimes installed:" in the generated output. Do not use dotnet --version, because this command only returns the version of the .NET command-line tools.

Console Application to Read Value from OPC Unified Architecture Server

  1. Open a command prompt.

  2. Create a folder named Hello and navigate to the folder.

  3. Type the following: dotnet new console. This command creates a project file (Hello.csproj) and a main program file (Program.cs).

  4. Type the following: dotnet add package OpcLabs.QuickOpc. This command adds OPC Data Client package reference to the project file.

    The above command actually adds a reference to the package corresponding always to the very latest OPC Data Client version. If you want to be sure that you referencing a package for OPC Data Client 2024.2, use dotnet add package OpcLabs.QuickOpc --version 5.81 command instead.
  5. Using a text editor, add following code to the beginning of the Program.cs file:

    using OpcLabs.EasyOpc.UA;
    
  6. 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);
    
  7. Save the changes to Program.cs.

  8. 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.            

Console Application to Read Value from OPC XML-DA Server

  1. Open a command prompt.

  2. Create a folder named HelloXml and navigate to the folder.

  3. Type the following: dotnet new console. This command creates a project file (HelloXml.csproj) and a main program file (Program.cs).

  4. Type the following: dotnet add package OpcLabs.QuickOpc. This command adds OPC Data Client package reference to the project file.

    The above command actually adds a reference to the package corresponding always to the very latest OPC Data Client version. If you want to be sure that you referencing a package for OPC Data Client 2024.2, use dotnet add package OpcLabs.QuickOpc --version 5.81 command instead.
  5. Using a text editor, add following code to the beginning of the Program.cs file:

    using OpcLabs.EasyOpc.DataAccess;
    
  6. 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);
    
  7. Save the changes to Program.cs.

  8. 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.            

See Also

Concepts

Examples