01-30-2014 03:08 AM
Hi All
I am wondering if it is possible to help. I'm using Ni-PCI-6229 Card but i am having trouble acquiring the data as it seems to be drifting (As seen in the attached file. The drift doesnt seem like a lot but over a period of time it makes a big difference).
The code is as follows
SetUpAIChannels is the setup of the card
ThreadLogData is the thread called by the program
LoadDataEvent is the event called when the buffer is full
Also i am inputting a 20Hz clock which i have checked on the ossilliscope.
Thank you in advance
class Common_DataThread
{
private Task continuousTask = new Task();
private AnalogMultiChannelReader reader;
private AsyncCallback LoadDataCall;
private void SetUpAIChannels(out Task ContTask)
{
//Used for determining which channels have been output too
List<int> lclDisplayedChannels = new List<int>();
//Create Task
Task lclContinuousTask = new Task();
//Create ai channel
AIChannel tempAIChannel;
for (int i = 0; i < Inter_DataInterface.GetNumberOfChannels(); i++)
{
try
{
if (Inter_DataInterface.DisplayTraceList(i) || Inter_DataInterface.EnabledList(i) || Inter_DataInterface.LogDataList(i))
{
//Setup channel if it is either displayed, logged or alarm is enabled
tempAIChannel = lclContinuousTask.AIChannels.CreateVoltageChannel(
DataLoggerV4.Properties.Settings.Default.DeviceUsed + "/" + Inter_DataInterface.ChannelList(i),
"Voltage " + System.Convert.ToString(i),
DataLoggerV4.Properties.Settings.Default.TerminalConfiguration, //E.g NRSE , RSE , Diff
-10,
10,
AIVoltageUnits.Volts);
lclDisplayedChannels.Add(i);
}
}
catch (DaqException)
{ }
//Only AI0 is active
}
// For this example only AI0 is used
//configure DAQ
lclContinuousTask.Timing.ConfigureSampleClock(
"", // external clock source line or use "" for internal clock
100000,// expected rate of external clock or actual rate of internal clock
SampleClockActiveEdge.Rising, // acquire on rising or falling edge of ticks
SampleQuantityMode.ContinuousSamples, // continuous or finite samples
5000 // number of finite samples to acquire or used for buffer size if continuous
);
//Check it is working
lclContinuousTask.Start();
//Stop task
lclContinuousTask.Stop();
//Set task to memory
continuousTask = lclContinuousTask;
//Set Number of displayed channels
DisplayedChannels = lclDisplayedChannels;
}
public void ThreadLogData()
{
try
{
continuousTask.Start();
reader = new AnalogMultiChannelReader(continuousTask.Stream);
reader.SynchronizeCallbacks = true;
LoadDataCall = new AsyncCallback(LoadDataEvent);
if (LoopStop == false)
{
LoopStop = Inter_ThreadInterface.GetStop();
reader.BeginReadWaveform((Convert.ToInt32(continuousTask.Timing.SamplesPerChannel)), LoadDataCall, continuousTask);
}
}
catch (DaqException ex)
{
MessageBox.Show(ex.Message);
continuousTask.Dispose();
}
}
void LoadDataEvent(IAsyncResult ar)
{
Boolean NewFile;
try
{
AnalogWaveform<double>[] DataCollection;
// End waveform a write all
DataCollection = reader.EndReadWaveform(ar);
//im reading using this function
DataCollection[0].GetRawData();
if (Inter_ThreadInterface.GetStop() == false)
{
reader.BeginReadWaveform(Convert.ToInt32(continuousTask.Timing.SamplesPerChannel), LoadDataCall, continuousTask);
}
else
{
continuousTask.Stop();
if (!(null == file))
{file.Close();}
}
}
catch
{
// continuousTask.Stop();
if (!(null == file))
{ file.Close(); }
}
}
}
01-31-2014 10:17 AM
Is the analog input open ?
Have you tested it with a shortcuted input?
Sounds like an open input and not path for the bias current.
01-31-2014 10:30 AM
02-03-2014 02:37 AM
Hi Dennis
We have tried the signal in ni max and the log was very accurate
The terminal configuration and device used is set as so:
tempAIChannel = lclContinuousTask.AIChannels.CreateVoltageChannel(
DataLoggerV4.Properties.Settings.Default.DeviceUsed + "/" + Inter_DataInterface.ChannelList(i),
"Voltage " + System.Convert.ToString(i),
DataLoggerV4.Properties.Settings.Default.TerminalConfiguration, //E.g NRSE , RSE , Diff
-10,
10,
AIVoltageUnits.Volts);
lclDisplayedChannels.Add(i);
}
We are using the internal clock because at points we select multiple channels and need to read from them.
02-03-2014 02:44 AM
Hi Henrik
The source is not open it is connected to a callibrated source which has been checked with a callibrated ocilliscope.
We are measuring voltage RSE or Differential and we are using a BNC-2090 series
Regards
Chris