Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NIDaqmx Python: Acquire Multichannel Analog input

Hello,

 

I am attempting to program a myDAQ device to acquire multichannel analag input  using the nidaqmx library in Python. 

I want to receive voltage data in 200kHz sampling rate.

however, when I try to change sampling rate to 200kHz, It does not work.

 

Here is a test code I have set up:

with nidaqmx.Task() as master_task, nidaqmx.Task() as slave_task:
    master = master_task.ai_channels.add_ai_voltage_chan("Dev1/ai2")
    slave = slave_task.ai_channels.add_ai_voltage_chan("Dev1/ai3")
    slave_task.timing.cfg_samp_clk_timing(200000)
    master_task.timing.cfg_samp_clk_timing(200000)
    print(slave_task.timing.samp_clk_rate)
    print(master_task.timing.samp_clk_rate)
    master_task.stop()
    slave_task.stop()
    
    master_data = master_task.read()
    slave_data = slave_task.read()

    i = 0
    tic = time.time()
    while True:
        master_data = master_task.read()
        slave_data = slave_task.read()
        toc = time.time()
        if i==0:
            Result = np.array([[(toc-tic)],[master_data],[slave_data]])
        else:
            Result = np.append(Result, [[(toc-tic)],[master_data],[slave_data]],axis=1)
        if Result[0,i] >= 10:
            break
        else:
            i = i +1
0 Kudos
Message 1 of 5
(6,258 Views)

Hi jasonim,

 

Can you describe in more detail what you mean by "does not work"? Is there a specific error message that you are getting, or what is the behavior?

Claire C.
AppSW Staff Product Support Engineer
National Instruments
CLD|CTD
0 Kudos
Message 2 of 5
(6,209 Views)

I use below code to set up sampling rate to 200kHz

slave_task.timing.cfg_samp_clk_timing(200000)
master_task.timing.cfg_samp_clk_timing(200000)

before I add above code to whole code, it works

however when I add this code to set up sampling rate, it does not work

when I executed whole code, python said "it is reserved another work" something like this

0 Kudos
Message 3 of 5
(6,198 Views)

I use below code to set up sampling rate to 200kHz

Before I added this code, sampling rate was 1000Hz

 

slave_task.timing.cfg_samp_clk_timing(200000)
master_task.timing.cfg_samp_clk_timing(200000)

However, when I try to whole code after adding above code

 

DaqError is displayed

 

DaqError: The specified resource is reserved. The operation could not be completed as specified. Task Name: _unnamedTask<5>

 

0 Kudos
Message 4 of 5
(6,170 Views)

Most DAQ devices won't support 2 distinct hw-clocked AI tasks at a time.  They only have 1 "timing engine" available to be shared across whatever AI channels you add to the task.  That's likely the reason for your error.

 

It appears you could simply put both channels in the same task as you seem to want them to sample at the same rate, and you're trying to start, read, and stop them at the same time.

 

I can't promise this is the *only* problem with the code -- I only program LabVIEW so I don't really know the text syntax or API.   I *will* mention that it's odd to configure your task(s), then immediately *stop* them (you haven't started them!), and then try to read from them.   It would be much more normal if those stop calls were starts instead.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 5 of 5
(6,156 Views)