03-01-2015 09:12 PM
Dear NI,
I was able to get same sort of analog input and output synchronization (as above) working. My application is nearly identical to that of Dr. Clements above also in neuroscience. One additional wrinkle for me is that I would like to be able to update the output buffer while it is being written to the NI Box basically staying a block or two ahead of the block being sent to the device. I'm using an NI-USB 6221 as are my colleagues.
Here is the relevant block of code to start the input and output routines.
...
// Set up input task
DAQmxErrChk (DAQmxCreateTask("", &m_NIUSBXInputTaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(m_NIUSBXInputTaskHandle, (LPCSTR)GetDeviceInputName(0), "", DAQmx_Val_RSE,
-10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk (DAQmxCreateAIVoltageChan(m_NIUSBXInputTaskHandle, (LPCSTR)GetDeviceInputName(1), "", DAQmx_Val_RSE,
-10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(m_NIUSBXInputTaskHandle, NULL, PER_CHANNEL_SAMPLE_RATE,
DAQmx_Val_Rising, DAQmx_Val_ContSamps, (uInt64)PER_CHANNEL_SAMPLE_RATE ));
DAQmxErrChk (GetTerminalNameWithDevPrefix(m_NIUSBXInputTaskHandle, "ai/StartTrigger", TriggerName));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(m_NIUSBXInputTaskHandle, DAQmx_Val_Acquired_Into_Buffer,SAMPLES_PER_BLOCK,
0,BufferedReadEveryNCallback,this));
// Set up output task
DAQmxErrChk (DAQmxCreateTask("",&m_NIUSBXOutputTaskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(m_NIUSBXOutputTaskHandle,GetDeviceOutputName(0),"",
-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAOVoltageChan(m_NIUSBXOutputTaskHandle,GetDeviceOutputName(1),"",
-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgOutputBuffer(m_NIUSBXOutputTaskHandle, OUTPUT_BUFFER_SIZE));
DAQmxErrChk (DAQmxCfgSampClkTiming(m_NIUSBXOutputTaskHandle,"",PER_CHANNEL_SAMPLE_RATE,
DAQmx_Val_Rising,DAQmx_Val_ContSamps,(uInt64)PER_CHANNEL_SAMPLE_RATE ));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(m_NIUSBXOutputTaskHandle, TriggerName, DAQmx_Val_Rising));
// Set all buffer values to zero initially.
// NOTE: This is the buffer I would like to update
for ( int i = 0; i < OUTPUT_BUFFER_SIZE; i++ )
m_NIOutputBuffer[i] = 0;
DAQmxErrChk (DAQmxWriteAnalogF64(m_NIUSBXOutputTaskHandle, SAMPLES_PER_BLOCK, FALSE,
DAQmx_Val_WaitInfinitely, DAQmx_Val_GroupByChannel,
m_NIOutputBuffer, NULL, NULL));
DAQmxErrChk (DAQmxStartTask(m_NIUSBXOutputTaskHandle));
DAQmxErrChk (DAQmxStartTask(m_NIUSBXInputTaskHandle));
--
03-02-2015 01:24 PM
Hi Brian,
Since this discussion thread is several years old I recommend starting a new thread just for your issue. It will give it more visibility on the NI Forums where NI and forum members can monitor it more closely.