.NET Programming

This chapter helps you get started using Zurich Instruments LabOne’s .NET API to control your instrument or integrate your instrument into an established .NET based control framework.

LabOne API documentation

This chapter and the examples are not intended to be a .NET and Visual Studio or an introduction to any specific programming language.

For a full reference of the .Net API visit the LabOne API documentation.

Installing the LabOne .NET API

Requirements

To use LabOne’s .NET API, ziDotNET, a Microsoft Visual Studio installation is required. The .NET API is a class library supporting x64 and win32 platforms. As the API is platform specific the project also needs to be platform specific.

The LabOne .NET API ziDotNET is included in a standard LabOne installation. No installation as such is required, but the corresponding dynamically linked library (DLL) files need to be copied to the folder of the Visual Studio solution, and a few configuration steps must be performed. The main LabOne installer is available from Zurich Instruments' download page.

Getting Started with the LabOne .NET API

This section introduces the user to the LabOne .NET API. In order to use the LabOne API for .NET applications two DLL libraries should be copied to the application execution folder. The libraries are platform specific. Therefore, the project platform of the project should be restricted either to x64 or win32 CPU architecture. The following figures illustrate the initial steps to create a C# project using the LabOne API. The setup for other languages like Visual Basic or F# is equivalent.

first steps 1
Figure 1. Creating a new C# project based on a solution.

Create a new project and choose Visual C# as a programming language and Console Application as target.

first steps 2
Figure 2. C# project with main program code opened in editor. Initially the project will support any CPU architecture. The ziDotNET API only supports x64 and win32 platforms.

The first step which needs to be done is to define the target platform as initially a Visual C# project is platform independent. To do this, click on the Active solution platform box, select Configuration Manager…​ to open the the Configuration Manager. In the following window click on the arrow under platform add a New target and choose x64 (Figure 3).

first steps 2 manager
Figure 3. C# project with main program code opened in editor. Initially the project will support any CPU architecture. The ziDotNET API only supports x64 and win32 platforms.

The LabOne API for .NET consists of two DLLs for each platform that supply all functionality for connecting to the LabOne Data Servers on the specific platform (x64 and win32) and executing LabOne Modules. For simplicity we only discuss the x64 platform in this section, but the needed steps are analogous for the win32 platform. For x64 the two DLLs are ziDotNETCore-win64.dll and ziDotNET-win64.dll. The two DLL must accompany the executable using the functionality. The DLL files are installed under your LabOne installation path in the API/DotNet folder (usually C:\Program Files\Zurich Instruments\LabOne\API\DotNET). Copy the two DLLs for your platform into the solution folder.

first steps 3
Figure 4. Reference to the API DLL ziDotNET for the specific platform.

To add the DLL to the project go to the solution explorer of your project (Figure 2) and right click on References and add the ziDotNET-win64.dll (Figure 4)

first steps 4
Figure 5. Added using zhinst; statement and code to open the connection to the server.

Figure 5 shows a first simple program which is done by adding using zhinst; to the include directive and the following code to the main body.

ziDotNET daq = new ziDotNET();
daq.init("localhost",8004,(ZIAPIVersion_enum)5);

If everything is configured correctly, the code compiles and when executed opens a session to a running LabOne data server and closes it before exiting the program.

LabOne .NET API Examples

The source code for the following program (Examples.cs) can be found in your LabOne installation path in the API/DotNet folder (usually C:\Program Files\Zurich Instruments\LabOne\API\DotNET).

The examples are documented in the LabOne API documentation.