12-10-2013 10:54 AM
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));
//
12-10-2013 11:37 AM
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?
12-10-2013 01:15 PM
12-13-2013 02:58 AM
solved the problem. The read function must be called with 2000 inbstead of 1000. 🙂