LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NI DAQmx slow read/write function

Good morning,

 

I'm using NI modules for simulation purpose, but i'm enocuntering some issue about the timing. I use C api to interface with modules.

 

My system has the following components:

 

- NI cDAQ-9189 -> Modules: 1x9205 7x9264

- NI cDAQ-9189 -> Modules: 4x9425, 4x9476

- NI cDAQ-9185 -> Module: 1x9474 (Used as frequency generator)

 

I'm using a windows pc for the communication with the NI devices.

 

To read/write all the resources from/to NI modules i need the following time:

 

- Input read: 6-7 ms

- Output write: 40-42 ms

 

- Digital input read: 5-6 ms

- Analog input read: 0,1-0,3 ms

- Digital output write: 5-6 ms

- Analog output write: 25-28 ms

- Frequency output write: 8-10 ms

 

The read/write operation is performed every 100 ms. I used the following functions for my purpose:

 

DI: 

DAQmxReadDigitalLines (m_taskHandleDI,-1,1.0,DAQmx_Val_GroupByScanNumber,m_digitalInputcallbackData.values,N_SIZE_DI,&numRead,&bytesPerSamp, Q_NULLPTR);

AI:

DAQmxReadAnalogF64(taskHandle, -1, 1.0, DAQmx_Val_GroupByScanNumber, data, N_SIZE_AI, &numRead, NULL)

DO:

DAQmxWriteDigitalU32(m_taskHandleDO,1,1,10.0,DAQmx_Val_GroupByChannel,dataDO,&written, Q_NULLPTR);

AO:

DAQmxWriteAnalogF64(m_taskHandleAO,1,1,1.0, DAQmx_Val_GroupByScanNumber, dataAO, &written, Q_NULLPTR);

FO:

DAQmxWriteCtrFreq(m_taskHandleFO,1,1,1.0,DAQmx_Val_GroupByScanNumber,freq,duty,&written,Q_NULLPTR)

 

I need to reduce the execution time to be able to execute come logic with 10ms time cycle.

 

There is any way to solve it or some workaround to improve performance? 

 

Best Regards.

 

Thanks

0 Kudos
Message 1 of 5
(821 Views)

Hi celad,

 


@celad wrote:

There is any way to solve it or some workaround to improve performance? 


In LabVIEW you would place the different DAQmx tasks in their own loops to handle them in parallel.

And you would use the "N channel N sample" mode with a proper sample timing for each task to allow reading/writing waveforms.

 

Have you tried the same in C?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 5
(804 Views)

Because i need to exchange information about the logic and the read/write signals on NI, the multiprcess approach would be last resort for this.

 

The application is quite complex and separating the NI part from the main execution would require a lot of effort.

 

Thanks for your answer.

 

Claudio

0 Kudos
Message 3 of 5
(800 Views)

I need to reduce the execution time to be able to execute come logic with 10ms time cycle.

 

There is any way to solve it or some workaround to improve performance? 

 

Best Regards.

 

Thanks


You can get a deterministic response by adopting an RT-based system instead of windows, in this case, you can transition to cRIO and achieve the 10ms cycle time. There are a bunch of overheads that the DAQmx driver has to manage to achieve the read/write.

 

Are you using software-timed I/O or hardware-timed I/O? (in other words, are you configuring sampling clock or not)

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 4 of 5
(787 Views)

You can improve the performance quite a bit by explicitly handling the DAQmx Task State transitions

 

See here

 

Essentially what you seem to have done implies state transition from verified to reserved to committed to run and all the way back since DAQmx will try to return the Task to the last explicitly set state.  This does take a finite time that you can bury with 1 call to commit the Task Resources during setup rather than implying the transitions for each read and write.

 

Knowing how DAQmx behaves under the hood let's you write more optimized code when you need the extra performance. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 5
(776 Views)