OPC Studio User's Guide and Reference
Getting Started under new .NET using Visual Studio Code
Client and Subscriber Development > Getting Started > Getting Started under .NET Framework or .NET > Getting Started under new .NET using Visual Studio Code
In This Topic

This article is for development with Visual Studio Code, a multi-platform source code editor developed by Microsoft. For development with "full" Visual Studio (Windows-only) IDE, see Getting Started under new .NET using IDE.

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 QuickOPC package reference to the project file.

    The above command actually adds a reference to the package corresponding always to the very latest QuickOPC version. If you want to be sure that you referencing a package for QuickOPC 2024.2, use dotnet add package OpcLabs.QuickOpc --version 5.81 command instead.
  5. Type the following: code . (note the dot '.' as a parameter to the command.) Visual Studio Code starts and its window opens.

  6. At this point, you might be asked "Required assets to build and debug are missing from 'vscode'. Add them?". If so, press the Yes button in the popup window.

  7. A notification will appear "There are unresolved dependencies from 'Hello.csproj'. Please execute the restore command to continue.". Press the Restore button in the popup window.

  8. In the Explorer window, click on the Program.cs file. The file opens in the code editor.

  9. Add following code to the beginning of the Program.cs file:

    using OpcLabs.EasyOpc.UA;
    
  10. 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);
    
  11. Select Debug -> Start Debugging (F5) from the menu, or press the corresponding button on the toolbar.

    This will build and launch the program. The value will be read from the OPC server and displayed in the Debug Console window.

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 QuickOPC package reference to the project file.

    The above command actually adds a reference to the package corresponding always to the very latest QuickOPC version. If you want to be sure that you referencing a package for QuickOPC 2024.2, use dotnet add package OpcLabs.QuickOpc --version 5.81 command instead.
  5. Type the following: code . (note the dot '.' as a parameter to the command.) Visual Studio Code starts and its window opens.

  6. At this point, you might be asked "Required assets to build and debug are missing from 'vscode'. Add them?". If so, press the Yes button in the popup window.

  7. A notification will appear "There are unresolved dependencies from 'Hello.csproj'. Please execute the restore command to continue.". Press the Restore button in the popup window.

  8. In the Explorer window, click on the Program.cs file. The file opens in the code editor.

  9. Add following code to the beginning of the Program.cs file:

    using OpcLabs.EasyOpc.DataAccess;
    
  10. 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);
    
  11. Select Debug -> Start Debugging (F5) from the menu, or press the corresponding button on the toolbar.

    This will build and launch the program. The value will be read from the OPC server and displayed in the Debug Console window.

See Also