04-02-2009 03:56 PM - edited 04-02-2009 04:00 PM
04-02-2009 03:58 PM - edited 04-02-2009 03:59 PM
Sorry, the previous post is messed up.
I'm using DAQmx USB6289 to collect data from 15 channels. sampling rate is 1khz. I use DAQmxRegisterEveryNSamplesEvent to continuously collect data. I have some questions regarding attaching time stamp to the data points.
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
DAQmxGetReadRelativeTo(taskHandle, position);
DAQmxSetReadRelativeTo(taskHandle,position[0]-50+1);// to get the most recent 50 data scan or sample?
DWORD currenttime = GetTickCount();/ /get the current time, which will be in the unit of ms.
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,g_nsample,10.0,DAQmx_Val_GroupByScanNumber,data,50*15,&read,NULL));
}
My questions are
1) for "DAQmxSetReadRelativeTo(taskHandle,position[0]-50+1);", will it point to the most recent 50 scan of data samples (50*15channels) or just most recent 50 data samples?
2) how to associate time stamps to the data? for example, I use " currenttime = GetTickCount();/ " right before 'DAQmxReadAnalogF64', can I directly use interval of 1ms to the collected data or scan?
for example, if the answer for question 1 is 'scan', then
DATA time stamp
data[1,1],data[1,2],....data[1,15] currentime-50+1
data[2,1],data[2,2],....data[2,15] currentime-50+2
....
data[50,1],data50,2],....data[50,15] currenttime
if the answer for question 1 is 'data sample', then
data[1,1], data[1,2],.... data[1,15]
currentime-49 ...............................
data[2,1], data[2,2],.... data[2,15]
(... currentime-5)
data[3,1], data[3,2],. data[3,5]
(currentime-4 currentime-3 currentime)
Am I correct?
This is the setting the DAQ connection:
void DataCollectionWin::ConnectDAQ() //for the connection part
{
DAQmxErrChk(DAQmxCreateTask ("", &taskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0,Dev1/ai1,Dev1/ai2,Dev1/ai3,Dev1/ai4,Dev1/ai5,Dev1/ai16,Dev1/ai17,Dev1/ai18,Dev1/ai19,Dev1/ai20,Dev1/ai21,Dev1/ai6,Dev1/ai7,Dev1/ai22","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,60000));
DAQmxSetReadOverWrite(taskHandle,DAQmx_Val_OverwriteUnreadSamps);
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,g_nsample,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
DAQmxErrChk (DAQmxStartTask(taskHandle));
}
04-03-2009 11:12 AM
It should read 50 samples for each channel.
If you read the data in as a waveform it will already have a timestamp associated with it.
04-03-2009 11:20 AM
Thank you for the reply. What do you mean read the data as a waveform? How to get the time stamp?
I collected some data and check the time intervals tween each group of data (50*15). Then I found the time intervals sometime below 50ms! I won't be suprised if it is larger than 50ms because the program is also taking time to save the data into a file after collection. But less than 50ms?? Does it mean the sample rate is faster than 1KHz? How's that happen?
04-03-2009 02:13 PM
How to read data as waveform using vc++? I can't find the function in the help file.
Thank you.
04-06-2009 07:43 AM
04-06-2009 12:34 PM
04-06-2009 12:53 PM
04-06-2009 04:52 PM
04-06-2009 05:25 PM - edited 04-06-2009 05:29 PM
Thank you, Doug. If I use DAQmxReadAnalogF64 to read out all the available data in the buffer, should the system time be associated to the first data or the last data in the buffer?
For example, if I put following setting (sample rate:1kz)
DWORD currenttime = GetTickCount();/ /get the current time, which will be in the unit of ms.
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,-1,10.0,DAQmx_Val_GroupByScanNumber,data,60000*15,&read,NULL));
then
1) data[1]: current time; data [2]: current time+1ms;....data [n]: current time+n-1ms or
2) data[read]: current time; data[read-1]:current time -1ms; data[read-n]: current time-n+1ms
Which one is correct? I previously set to read 50 most recent data samples (see above). But it seems there are overlaps between the groups (50 samples each group). It shows sometimes the intervals between two groups are less than 50 ms, which is expected to be the minimum interval for reading 50 samples since the sampling rate is 1kz. Also I read some previous posts regarding the time difference between the actual hardware aquiring the data and the software reading the data. How to get round of this issue?
In addition, if I read out all the available data, how to set "arraySizeInSamps"? Should I just use a array size as large as possible? Thank you.