05-09-2023 07:44 AM
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!
05-09-2023 09:12 AM
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.
05-09-2023 10:21 AM
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.
05-09-2023 10:40 AM
@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.
05-09-2023 12:23 PM
as ZYong pointed out, you should time only the portion after DAQmx Start Task and the time it completes the expected read.
05-10-2023 02:31 AM
Thank you for the clarification.
Now I understand the reason behind the slower execution speed.
I will try my best using C.