Setting up (C#)

To start working with openDAQ™, the requisite binaries are required. They can be obtained at the openDAQ™ documentation and releases webpage or from http://nuget.org (recommended way).

The .NET binaries are currently only available in the Windows™ SDK packages. For Linux™ they are included in the NuGet package, although here the .NET Bindings are not tested.

All commands in this guide use the .NET command-line interface (dotnet CLI) which is a cross-platform toolchain for developing, building, running, and publishing .NET applications.

Creating an openDAQ™ project

Below, we start a Console Project in Visual Studio™ from scratch but there are also example files which can be found in the examples archive from the openDAQ™ documentation and releases webpage.

Requirements

  • Windows

  • Linux

  • .NET compiler, e.g.

    • .NET SDK (used in this guide).

    • Visual Studio 2022™.

    • Visual Studio Code with extension "C# Dev Kit".

On Windows there is the Windows Subsystem for Linux (WSL) (use an Ubuntu 22.04 distribution) where the cross-compiled executable can be tested.
See also points 2 and 3 on the Linux tab.
  • Ubuntu 22.04 (see also the note below).

  • On Windows™ users can just cross-compile the project for Linux™ using the Windows™-requirements (used in this guide).

  • For development (not tested) and running on Linux™:
    Install .NET SDK or .NET Runtime on Ubuntu.

  • Alternatively (cross-) compiled projects can be run on Windows Subsystem for Linux (WSL) (use an Ubuntu 22.04 distribution).

In general everything around .NET can be found here:
https://dotnet.microsoft.com/en-us/download/dotnet/8.0

Creating and building the project

In this guide we use a Developer PowerShell for VS2022 prompt on Windows™ for creating and (cross-) building the project.
To run the result of the cross-compilation we use a bash prompt on Linux™ (or WSL on Windows™).

To start, create a csharp/quick_start directory and navigate to it.

With the following commands:

  • we first create an empty (.NET8.0) console application project

  • and then we add the openDAQ.Net Bindings NuGet package reference (from nuget.org) to the project, which contains all the needed binaries.

dotnet new console
dotnet add package openDAQ.Net
Alternatively, the latest version of the .NET Bindings is available at https://docs-dev.opendaq.com/ and can be used via:
dotnet add package openDAQ.Net --source path/to/folder
See also Learn NET - dotnet add package

With this, we are ready to start developing:
We fill in our Program.cs executable code as follows (replacing the default content):

using Daq.Core.Types;
using Daq.Core.Objects;
using Daq.Core.OpenDAQ;

// Create a fresh openDAQ(TM) instance, which acts as the entry point into our application
Console.WriteLine("create instance...");
var instance = OpenDAQFactory.Instance();

Console.WriteLine();
Console.WriteLine($"successfully created the instance '{instance.Name}'");

Console.WriteLine();
Console.Write("Press a key to exit the application ...");
Console.ReadKey(intercept: true);
When creating the openDAQ™ instance, we don’t need to specify the root directory of our openDAQ™ Modules as they are conveniently being deployed by the NuGet package and found where they are.

Now we can compile and run our program in our PowerShell™ instance from above.

  • Windows

  • Linux

dotnet run

Cross-compiling on Windows™ and running the result on Linux™ using WSL:

dotnet build --runtime linux-x64
wsl
cd ./bin/Debug/net8.0/linux-x64/
./quick_start
exit
dotnet build --runtime linux-x64 builds the console application for Linux™ and uses the associated binaries from the NuGet package. The result (./bin/Debug/net8.0/linux-x64/quick_start) can then be run in WSL under Ubuntu 22.04 (see Requirements above).

With the run command the project is being built (when there was a change after the last run) and the resulting quick_start.exe executed.
All binaries from the Nuget package will be copied to the target directory (which defaults to ./bin/Debug/net8.0). These dependencies are also entered in the file quick_start.deps.json so that the executable can find the openDAQ™ SDK binaries during execution.

Congratulations, if you managed to reach this point, you have successfully created your first openDAQ™ project!
To find out more about using openDAQ™ applications to connect to, configure, and read data of Devices, continue with the openDAQ™ application quick start guide.