Skip to main content
Skip table of contents

C# .NET for LJM - Windows

C# .NET examples for the LJM library.

Prerequisites

  • A T-series LabJack Device

  • LJM Library and .NET assembly - Install the LJM Library

  • .NET 2.0 Framework or newer for the LJM .NET assembly

  • Visual Studio 2022 or newer, or .NET SDK 6 or newer, for projects.

  • Operating system - Windows

Latest Release Example Package

CSharp_DotNet_LJM_Examples_2024_10_23.zip

New Changes

  • Initial C# only release with T8, T7 and T4 examples.

GitHub

Our latest example changes are available in our GitHub repository.

Instructions

  1. Go to the Quickstart Tutorial for your device and follow the steps to install LabJack software and confirm basic operation.

  2. Download/extract the .zip file attached at the top of this page.

  3. Navigate to the extracted CSharp_DotNet_LJM_Examples folder.

  4. Open the example projects in Visual Studio or Visual Studio Code to edit, build and run.

Refer to the download's README.txt file for more details. 

Where is an example to do XYZ?

You will find lots of examples in this archive, but there is not an example for everything the LabJack can do.  The reason for this stems from the "Overview" section above.  Most operations simply involve writing and reading different registers, so you really just need examples that show you how to write and read any register.  If we had examples for every operation, they would just be copies of the example "Write Read Loop with Config" with different registers. The typical workflow to do almost anything beside stream is:

  1. Look at the T-series Datasheet or the Modbus Map to determine what registers you need to write and read.

  2. Use the Register Matrix in Kipling to test writing and reading your desired registers and confirm you see what you expect to see.  This step is optional and not always applicable.

  3. Use eWriteName (or eWriteNames) to write the desired registers and eReadName (or eReadNames) to read the desired registers. Or just use "Write Read Loop with Config", which provides the basic structure used by many user applications.

Code Snippets

CODE
using System;
using LabJack;

namespace ReadSerialNumber
{
    class ReadSerialNumber
    {
        static void Main(string[] args)
        {
            int handle = 0;
            try
            {
                //Open first found LabJack.
                LJM.OpenS("ANY", "ANY", "ANY", ref handle);
                
                //Call eReadName to read the serial number from the LabJack.
                string name = "SERIAL_NUMBER";
                double value = 0;
                LJM.eReadName(handle, name, ref value);

                Console.WriteLine("eReadName result: ");
                Console.WriteLine("  " + name + " = " + value);
            }
            catch (LJM.LJMException e)
            {
                Console.Out.WriteLine("Error: " + e.ToString());
            }
        }
    }
}

Old Versions

For older versions, go to the deprecated C#, VB .NET for LJM - Windows page.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.