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
Go to the Quickstart Tutorial for your device and follow the steps to install LabJack software and confirm basic operation.
Download/extract the .zip file attached at the top of this page.
Navigate to the extracted CSharp_DotNet_LJM_Examples folder.
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:
Look at the T-series Datasheet or the Modbus Map to determine what registers you need to write and read.
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.
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
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.