using System;
using MccDaq;
using System.IO;
namespace AnalogInDigitalTrigger
{
class Program
{
public const int BLOCKSIZE = 50;
public const int CHANCOUNT = 4;
public const int FIRSTCHANNEL = 0;
public const int LASTCHANNEL = 3;
public const int FREQ = 100;
public const int BUFFERSIZE = BLOCKSIZE * CHANCOUNT;
public const int HALFBUFFSIZE = BUFFERSIZE / 2;
public const string DEVICE = "1608G";
public static StreamWriter fStream;
static void Main(string[] args)
{
MccDaq.ErrorInfo RetVal;
int BoardNum = 0;
int DeviceChannels = 0;
int Rate = FREQ;
BoardNum = GetBoardNum(DEVICE);
if (BoardNum == -1)
Console.WriteLine("No USB-{0} detected!", DEVICE);
else
{
MccBoard daq = new MccDaq.MccBoard(BoardNum);
daq.BoardConfig.GetNumAdChans(out DeviceChannels);
if (DeviceChannels > 8)
Console.WriteLine("Single-Ended Channels");
else
Console.WriteLine("Differentially-Ended Channels");
IntPtr buffer = MccService.ScaledWinBufAllocEx(BUFFERSIZE);
if (buffer == IntPtr.Zero)
{
Console.WriteLine("Bad Handle");
return;
}
short[] chArray = new short[CHANCOUNT];
Range[] chRange = new Range[CHANCOUNT];
chArray[0] = 0;
chArray[1] = 1;
chArray[2] = 2;
chArray[3] = 3;
chRange[0] = Range.Bip10Volts;
chRange[1] = Range.Bip10Volts;
chRange[2] = Range.Bip10Volts;
chRange[3] = Range.Bip10Volts;
RetVal = daq.ALoadQueue(chArray, chRange, CHANCOUNT);
IsError(RetVal);
//specify ScanOptions.ExtTrigger to use the TRIG input
ScanOptions MyScanOptions = ScanOptions.Background |
ScanOptions.ScaleData |
ScanOptions.ExtTrigger |
ScanOptions.Continuous;
//setup the acquisiton
RetVal = daq.AInScan( FIRSTCHANNEL,
LASTCHANNEL,
BUFFERSIZE,
ref Rate,
Range.Bip10Volts,
buffer,
MyScanOptions
);
IsError(RetVal);
int Count = 0;
int Index = 0;
short daqStatus;
bool ReadLower = true;
double[] theArray = new double[BUFFERSIZE];
fStream = new StreamWriter(@"C:\Users\Public\Documents\DataFile1608G.asc");
CreateFileHeaders(chArray); //writes basic info to the beginning of the file
Console.WriteLine("Waiting for External TTL trigger...Press any key to exit loop.");
//Loop until key press
do
{
RetVal = daq.GetStatus(out daqStatus, out Count, out Index, FunctionType.AiFunction);
if ((Index >= HALFBUFFSIZE) & ReadLower) //check for 50% more data
{
//get lower half of buffer - ScaledWinBufToArray returns engineering units
RetVal = MccService.ScaledWinBufToArray(buffer, theArray, 0, HALFBUFFSIZE);
IsError(RetVal);
DisplayData(theArray, HALFBUFFSIZE / CHANCOUNT);
ReadLower = false; //flag that controls the next read
}
else if ((Index < HALFBUFFSIZE) & !ReadLower)
{
//get the upper half - ScaledWinBufToArray returns engineering units
RetVal = MccService.ScaledWinBufToArray(buffer, theArray, HALFBUFFSIZE, HALFBUFFSIZE);
IsError(RetVal);
DisplayData(theArray, HALFBUFFSIZE / CHANCOUNT);
ReadLower = true;//flag that controls the next read
}
} while (!Console.KeyAvailable);
RetVal = daq.StopBackground(FunctionType.AiFunction);
IsError(RetVal);
MccService.WinBufFreeEx(buffer);
WaitForKey();
}
}