03-06-2015 11:55 AM
Using NI example code, I am able to synchronize reading succesive NI analog input blocks with writing a buffer to NI analog outputs starting at the same sample. One additional thing that I need is that once the input and output are underway I want to be able to modify the output buffer being sent to the NI USB-6221 while retaining the sychronization of the input and output.
Is this possible?
Here is the startup code to give an idea of what I'm doing:
...
// 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_NIUSBXInputTaskHan
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(m_NIUSBXInputTask
0,BufferedReadEveryNCallback,this));
// Set up output task
DAQmxErrChk (DAQmxCreateTask("",&m_NIUSBXOutputTaskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(m_NIUSBXOutputTaskHandle
-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAOVoltageChan(m_NIUSBXOutputTaskHandle
-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgOutputBuffer(m_NIUSBXOutputTaskHandle, OUTPUT_BUFFER_SIZE));
DAQmxErrChk (DAQmxCfgSampClkTiming(m_NIUSBXOutputTaskHandle,""
DAQmx_Val_Rising,DAQmx_Val_ContSamps,(uInt64)PER_C
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(m_NIUSBXOutputTaskHandle
// Set all buffer values to zero initially.
// NOTE: This is the buffer I would like to update...either from an NI callback or I can do it from a
// separate Windows thread I'm running.
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-12-2015 10:24 AM
Hello,
I think there is a great example for you to use that comes with CVI which can be found by clicking Find Examples on the splash screen or Help >> Find Examples in your project. From there, click into Optimizing Applications >> Multithreading. In that folder there is a project that is called BuffNoDataLoss that shows how to create a thread safe queue and setup a producer/consumer type program. In this example the data is a random sine wave but could be adapted to your application.