Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

NI 9219 - Reading two tasks with Python

Solved!
Go to solution

Hello, I am trying to measure two channels on a NI 9219 but am having issues when I increase my sample rate. I want to take 20 samples at 100Hz for each channel at the same time. Is this possible? Below is some of my code. I am getting the following error 

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

Status Code: -50103
import time as t
import nidaqmx
import numpy as np

vCH = 'cDAQ9184-NGIALSMod3/ai1'
pCH = 'cDAQ9184-NGIALSMod3/ai0'

fSampling = 100.0  # Hz
nSamples = 20  # samples

def vcMeasure(vCH, pCH, dtMax):
    with nidaqmx.Task() as task, nidaqmx.Task() as task2:

        # Pressure
        task2.ai_channels.add_ai_bridge_chan(pCH, units=nidaqmx.constants.VoltageUnits.FROM_CUSTOM_SCALE,
                                            custom_scale_name="Pendo")
        task2.timing.cfg_samp_clk_timing(fSampling)


        # Volume
        task.ai_channels.add_ai_bridge_chan(vCH, units=nidaqmx.constants.VoltageUnits.FROM_CUSTOM_SCALE,
                                            custom_scale_name="Load")
        task.timing.cfg_samp_clk_timing(fSampling)

        xs = []
        ys = []
        xs2 = []
        ys2 = []
        t1 = t.time()
        t2 = t.time()
        dt = t2 - t1

        while dt < dtMax:
            data2 = task2.read(number_of_samples_per_channel=nSamples)
            data = task.read(number_of_samples_per_channel=nSamples)

            sampAV = sum(data) / len(data)
            sampAVP = sum(data2) / len(data2)
            t2 = t.time()
            dt = t2 - t1

            xs.append(dt)
            ys.append(sampAV)
            xs2.append(dt)
            ys2.append(sampAVP)
            print('time: ', dt)

    xs = np.array(xs, dtype=np.float64)
    ys = np.array(ys, dtype=np.float64)
    xs2 = np.array(xs2, dtype=np.float64)
    ys2 = np.array(ys2, dtype=np.float64)

    return xs, ys, xs2, ys2
0 Kudos
Message 1 of 6
(262 Views)
Highlighted

Hi nordec,

 

You can configure this to work at faster speeds than 2Hz by changing the ADC Timing Mode Property as shown in the article below (for LabVIEW). If you're in thermocouple measurement mode (High speed 20ms conversion time), then I don't expect you to be able to operate at those speeds. It'll be at the spec limit if you won't have much margin for error (high speed 10 ms conversion time).

How Can I Sample at More Than 2Hz with My NI 9212, 9213, 9214, 9=and 9219?

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000PAaKSAW&l=en-US

 

I found the equivalent property listed in some Python DAQmx documentation.

https://nidaqmx-python.readthedocs.io/en/latest/ai_channel.html

nidaqmx.constants.ADCTimingMode

 

Best,

Ben

Message 2 of 6
(227 Views)

Hi Ben,

 

When  I run only one channel I can get the rate I am looking for but when switching to two channels I am unable to get that same rate. Would the ADC timing still govern this?

 

Thank you

0 Kudos
Message 3 of 6
(220 Views)

Hi nordec,

 

I would expect it to govern this, but maybe I'm missing something.

 

What rate are you able to implement a single channel at that you can't implement on multiple channels?

Have you been able to identify the maximum rate you can run at when running multiple channels?

 

Best,

Ben

0 Kudos
Message 4 of 6
(212 Views)

I can implement a single channel at 100 Hz and I cannot run it at all with two channels. I am getting an error that the resource is reserved when trying to read the second channel in my loop. Do I have  to stop the first task before running another on a different channel? Or should I be able to read one task while another is being read? 

0 Kudos
Message 5 of 6
(202 Views)
Solution
Accepted by topic author nordec
03-25-2019 03:25 AM

That's a good point. And one that I missed earlier when working on the higher speed analog inputs.

This module can only run one input task at a time (please see the links below).

How Many DAQmx Tasks Can I Run Simultaneously

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019KWYSA2&l=en-US

 

This also gets addressed in our article regarding the original error message you were seeing:

 

Error -50103 when Using NI-DAQmx with Support for LabVIEW

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8kmSAC

 

Best,

 

Ben

Message 6 of 6
(182 Views)