Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing 2 analog inputs and 1 analog output in 6211

Hi all,

Maybe this question is currently answered. When I use single input it seems that no problem is occured. But wen it comes to 2 inputs, all I can observe is zero. Any reference for further reading and comments are appretiated. Sorry if this topic is already discussed.

 

Here is my code written in 6211:

int curBuffer = 0;

int buffer_size = 2000; //#samples to read
float sampling_rate_hz = 50000.0;
char channels[] = "Dev1/ai1:2"; //#this can be one channel or many...
float64 AIdata[2][2000];
HANDLE mutex_buffer;
extern int ufuk = 9;
int NIDAQmx_dataAccess_init(char* errBuff)
{


int32 readAI;
int32 error=0;
char trigName[256];
float64 AOdata[1000];
float64 phase=0.0;

 


mutex_buffer = CreateMutex( NULL, FALSE, NULL);
/*********************************************/
// DAQmx Configure Code
/*********************************************/

DAQmxErrChk (DAQmxCreateTask("",&AItaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(AItaskHandle,channels,"",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(AItaskHandle,"",sampling_rate_hz,DAQmx_Val_Rising,DAQmx_Val_ContSamps,buffer_size));
DAQmxErrChk (GetTerminalNameWithDevPrefix(AItaskHandle,"ai/StartTrigger",trigName));

 

DAQmxErrChk (DAQmxCreateTask("",&AOtaskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(AOtaskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(AOtaskHandle,"",sampling_rate_hz,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(AOtaskHandle,trigName,DAQmx_Val_Rising));

 

DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(AItaskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));

DAQmxErrChk (DAQmxRegisterDoneEvent(AItaskHandle,0,DoneCallback,NULL));

 

GenSineWave(1000,2.0,1.0/1000,&phase,AOdata);

 

DAQmxErrChk (DAQmxWriteAnalogF64(AOtaskHandle, 1000, FALSE, 10.0, DAQmx_Val_GroupByChannel, AOdata, NULL, NULL));

 

/*********************************************/
// DAQmx Start Code
/*********************************************/


DAQmxErrChk (DAQmxStartTask(AOtaskHandle));
DAQmxErrChk (DAQmxStartTask(AItaskHandle));

 

And in the function call back EveryNCallback I read the inputs.

/*********************************************/
// DAQmx Read Code
/*********************************************/
// getMutex
WaitForSingleObject(mutex_buffer, INFINITE);

 

DAQmxErrChk (DAQmxReadAnalogF64(AItaskHandle,1000,10.0,DAQmx_Val_GroupByChannel,AIdata[curBuffer],1000,&readAI,NULL));
//

 

 

0 Kudos
Message 1 of 4
(5,824 Views)

Hi,

 

When you run the code, what happens? Does it cause an error or does the data not show up correctly?

 

Have you tried modifying the "SynchAI-AO" example to include two channels?

Evan See
National Instruments
0 Kudos
Message 2 of 4
(5,820 Views)
Hi Evan. Pleased with your reply.
As I tried to say the inputs (aidata) becomes zero. I think this is the default value i assigned.
I started with synchaiao code. As you catch, my aim is to generate the double analog input version of this code. What i did is only to give the corresponding inputs (dev1/ai2:3) to the code u mentioned. And also i doubled the buffer size to implement two channels.
0 Kudos
Message 3 of 4
(5,814 Views)

solved the problem. The read function must be called with 2000 inbstead of 1000. 🙂

0 Kudos
Message 4 of 4
(5,791 Views)