Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize Continous Analog Input with UPDATED Output

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_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...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));

 

 

--

Dr. Brian Turnquist
Professor, Chair
Bethel University
Mathematics and Computer Science
St Paul, Minnesota 55112

 

0 Kudos
Message 1 of 2
(4,884 Views)

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. 

Warm Regards,

Josh
0 Kudos
Message 2 of 2
(4,805 Views)