LABJACK CODE:
//-----------------------------------------------------------------------------
// SingleAIN.cs
//
// Demonstrates reading a single analog input (AIN) from a LabJack.
//
// support@labjack.com
//-----------------------------------------------------------------------------
using System;
using LabJack;
namespace SingleAIN
{
class SingleAIN
{
static void Main(string[] args)
{
SingleAIN sAIN = new SingleAIN();
sAIN.performActions();
}
public void showErrorMessage(LJM.LJMException e)
{
Console.Out.WriteLine("LJMException: " + e.ToString());
Console.Out.WriteLine(e.StackTrace);
}
public void performActions()
{
int handle = 0;
int devType = 0;
int conType = 0;
int serNum = 0;
int ipAddr = 0;
int port = 0;
int maxBytesPerMB = 0;
string ipAddrStr = "";
try
{
//Open first found LabJack
LJM.OpenS("ANY", "ANY", "ANY", ref handle); // Any device, Any connection, Any identifier
//LJM.OpenS("T7", "ANY", "ANY", ref handle); // T7 device, Any connection, Any identifier
//LJM.OpenS("T4", "ANY", "ANY", ref handle); // T4 device, Any connection, Any identifier
//LJM.Open(LJM.CONSTANTS.dtANY, LJM.CONSTANTS.ctANY, "ANY", ref handle); // Any device, Any connection, Any identifier
LJM.GetHandleInfo(handle, ref devType, ref conType, ref serNum, ref ipAddr, ref port, ref maxBytesPerMB);
LJM.NumberToIP(ipAddr, ref ipAddrStr);
Console.WriteLine("Opened a LabJack with Device type: " + devType + ", Connection type: " + conType + ",");
Console.WriteLine("Serial number: " + serNum + ", IP address: " + ipAddrStr + ", Port: " + port + ",");
Console.WriteLine("Max bytes per MB: " + maxBytesPerMB);
//Setup and call eReadName to read from an AIN on the LabJack.
string name = "AIN0";
double value = 0;
LJM.eReadName(handle, name, ref value);
Console.WriteLine("\n" + name +" reading : " + value.ToString("F4") + " V");
}
catch (LJM.LJMException e)
{
showErrorMessage(e);
}
LJM.CloseAll(); //Close all handles
Console.WriteLine("\nDone.\nPress the enter key to exit.");
Console.ReadLine(); //Pause for user
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Globalization;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}