PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

Slow acquisition speed with PXIe system and Python

Hello!

 

With my current PXIe system and Python code, my data acquisition is very slow.

 

I am using the following components:

- Chassis: PXIe-1092

- Controller: PXIe-8398 & PCIe-8398 (in a x16 PCIe slot)

- Analog Input module: PXIE-6349, connect to BNC-2115 and BNC-2110 terminal blocks.

(- Analog Output module: PXIe-4322)

 

My PC specs are:

- Processor: AMD Ryzen 7 2700X Eight-Core Processor 4.00 GHz

- RAM: 64.0 GB

- OS: Windows 11 Pro

 

My acquisition software is Python (Spyder, Python V3.10) using the nidaqmx module.

 

My goal is to acquire data with the following specs:

- Number of channels: 30

- Sampling rate: 50 kS/s

- Duration: 100 ms

 

This is my code:

import nidaqmx as ni
import time

# Recording time
t_rec = 0.1

# Sample rate
sr = 50000

# Number of samples
samples = int(t_rec*sr)

# Get the start time
st = time.time()

with ni.Task() as task:
        
    task.ai_channels.add_ai_voltage_chan("PXI_I1/ai0:29")

    # Configure timing of analog reading task to acquire a finite amount of data once the task is started
    task.timing.cfg_samp_clk_timing(rate=sr, source='OnboardClock', samps_per_chan = samples)
        
    indata = task.read(number_of_samples_per_channel = ni.constants.READ_ALL_AVAILABLE)

# Get the end time
et = time.time()

# Get the execution time
elapsed_time = et - st
print('Execution time:', elapsed_time, 'seconds')

 

The acqusition time is approximately 630 ms using this code, hence 530 ms purely for the data transfer.

A python float is 64 bit, so my data amount is 64(bit)*5000(samples)*30(channels) = 9.600.000 bit = 9.6 Mbit.

This leads to a transfer rate of roughtly 20 Mbit/s or 2.5 Mbyte/s, which is incredibly slow in my opinion (I am not an expert though).

It can't be that this is all I can get using this system. It should be able to achieve GB/s transfer rates, so I must be doing something wrong.

 

If more information is necessary, let me know.

Any help is appreciated 🙂

 

Thanks!

 

 

0 Kudos
Message 1 of 6
(1,763 Views)

You are taking the execution time for Add Channel, Configure Timing and Read. DAQmx device takes some time to respond to the configuration API and to arm the device. To benchmark the actual performance, you should only take the time after you call task.start().

Moreover, Python runs extremely slow compared to C programming. How Fast Is C++ Compared to Python? | by Naser Tamimi, shows that Python takes 25 times more time to run the same algorithm compared to C++. If you care about the execution speed, you should use C or C# instead. See Using NI-DAQmx in Text Based Programming Environments to learn more.

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
0 Kudos
Message 2 of 6
(1,745 Views)

Thank you for the reply!

 

All these "Add Channel, Configure Timing and Read" are necessary to get the data, so i should count them in.

I have just put the time measurement before and after the "read" command, and the result is the same.

 

I have doubts on whether to trust in C++ to solve this issue, but I will try tomorrow and see, I've never used C before.

In the article you linked it also says that Python can be just as fast as C++ for the given example thanks to built-in functions.

 

0 Kudos
Message 3 of 6
(1,724 Views)

@felixfischer wrote:

In the article you linked it also says that Python can be just as fast as C++ for the given example thanks to built-in functions.

 


Unfortunately, NI-DAQmx Python API is a python wrapper on the C library. There is no built-in python library for NI-DAQmx. The wrapper layer contributes a lot of execution time.

I am giving recommendations based on my experience. I have used NI-DAQmx on LabVIEW, C, C# (.NET) and Python.

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
0 Kudos
Message 4 of 6
(1,719 Views)

as ZYong pointed out, you should time only the portion after DAQmx Start Task and the time it completes the expected read.

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 5 of 6
(1,708 Views)

Thank you for the clarification.

 

Now I understand the reason behind the slower execution speed.

 

I will try my best using C.

0 Kudos
Message 6 of 6
(1,678 Views)