Skip to content

Instantly share code, notes, and snippets.

@dmd
Created January 15, 2013 16:38
Show Gist options
  • Save dmd/4539958 to your computer and use it in GitHub Desktop.
Save dmd/4539958 to your computer and use it in GitHub Desktop.
using System;
using MeasurementComputing.DAQFlex;
using System.Threading;
namespace aincons
{
class MainClass
{
public static DaqDevice device;
public static int aimaxcount;
public static void Main (string[] args)
{
string[] deviceNames;
string deviceName;
deviceNames = DaqDeviceManager.GetDeviceNames (DeviceNameFormat.NameAndSerno);
int deviceNumber = 0;
try {
deviceName = deviceNames [deviceNumber];
} catch (IndexOutOfRangeException) {
Console.WriteLine ("No analog input device detected. (Not plugged in?)");
return;
}
device = DaqDeviceManager.CreateDevice (deviceName);
device.SendMessage("AI{0}:RANGE=BIP10V");
device.SendMessage("AI{0}:CHMODE=DIFF");
device.SendMessage("AI{1}:RANGE=BIP10V");
device.SendMessage("AI{1}:CHMODE=DIFF");
aimaxcount = (int)device.SendMessage("@AI:MAXCOUNT").ToValue();
device.SendMessage("AISCAN:LOWCHAN=0");
device.SendMessage("AISCAN:HIGHCHAN=1");
device.SendMessage("AISCAN:RATE=2000");
var timer = new System.Timers.Timer(5);
timer.Elapsed += new System.Timers.ElapsedEventHandler(getsamples);
timer.Enabled = true;
Console.ReadLine();
DaqDeviceManager.ReleaseDevice(device);
}
private static void getsamples (object myobject, System.Timers.ElapsedEventArgs e)
{
double[,] scanData;
device.SendMessage("AISCAN:SAMPLES=10");
device.SendMessage("AISCAN:START");
scanData = device.ReadScanData (10, 0);
int devbound = scanData.GetUpperBound(0);
int sampbound = scanData.GetUpperBound(1);
for (int dev = 0; dev <= devbound; dev++)
{
Console.Write(dev + ": ");
for (int sam = 0; sam <= sampbound; sam++)
{
Console.Write("{0},",(scanData[dev,sam] * 20 / aimaxcount - 10));
}
Console.WriteLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment