Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Digital Triggering with NI PCI-6132 in python nidaqmx

I'm using the python (v3.6) API nidaqmx (https://nidaqmx-python.readthedocs.io/) to interface with an NI PCI-6132 Multifunction DAQ card on a Windows 10 PC. 

 

I'd like to be able to use a digital trigger to start the acquisition of two analog signals, but have a number of issues.

 

First, in adding a channel to a task, the names of the inputs on the PCI-card (http://www.ni.com/documentation/en/multifunction-io-device/latest/pci-6132/pinout/) seemingly do not correspond to the names in nidaqmx. For example, AI0 is actually "ai0" but P0.0 is actually "port0/line0". Where is there documentation that lists the nidaqmx names of the various inputs for the PCI-6132. I have not been able to figure out how to add one of the PFI inputs as a channel specifically. 

 

Second, in order to use an input (analog or digital) is it necessary to first add that input as a channel to the task which it is triggering? For an analog trigger, this seems to be true. I have been completely unsuccessful in setting up a digital trigger. Below is my attempt at code which uses P0.0 as a digital trigger to a digital stream reader task. If you remove the trigger setup statements, the code runs fine.

 

###

import nidaqmx
from nidaqmx.constants import TriggerType, Edge, AcquisitionType, TaskMode, LineGrouping

 

with nidaqmx.Task() as trig_task:

    trig_task.di_channels.add_di_chan('Dev1/port0/line0', line_grouping=LineGrouping.CHAN_PER_LINE)
    trig_reader = DigitalSingleChannelReader(trig_task.in_stream)

    #set up digital trigger
    trig_task.triggers.start_trigger.trig_type = TriggerType.DIGITAL_EDGE
    trig_task.triggers.start_trigger.cfg_dig_edge_start_trig(trigger_source = "Dev1/port0/line0", trigger_edge = Edge.RISING)

 

    trig_task.start()
    dig_data = np.zeros(n_dig_samples, dtype=np.uint8)
    trig_reader.read_many_sample_port_byte(dig_data, n_dig_samples, timeout=10)

###

 

This code fails for me with error:

 

Traceback (most recent call last):
File "test_NI_DAQmx_digital_trigger.py", line 42, in <module>
trig_task.triggers.start_trigger.trig_type = TriggerType.DIGITAL_EDGE
File "C:\ProgramData\Anaconda3\lib\site-packages\nidaqmx\_task_modules\triggering\start_trigger.py", line 1838, in trig_type
check_for_error(error_code)
File "C:\ProgramData\Anaconda3\lib\site-packages\nidaqmx\errors.py", line 127, in check_for_error
raise DaqError(error_buffer.value.decode("utf-8"), error_code)
nidaqmx.errors.DaqError: Specified property is not supported by the device or is not applicable to the task.
Property: DAQmx_StartTrig_Type

Task Name: _unnamedTask<0>

Status Code: -200452

 

Lastly, I would like to actually use a digital trigger to start a task which does analog acquisition. How does one approach this? The nidaqmx examples (https://github.com/ni/nidaqmx-python/tree/master/nidaqmx_examples) and the usage documentation fall far short of explaining how to use the majority of this API's even basic functionality. 

 

Thank you!

Jake Connors

0 Kudos
Message 1 of 3
(4,020 Views)

You can simulate devices using NI-MAX.

 

I am in no way an expert, but when you simulate you can see the process.

Add a task. Then add a channel. That is the way it seems to work.

 

No clue about Python.

 

 

0 Kudos
Message 2 of 3
(4,003 Views)

I only use LabVIEW with DAQmx so I can't help with most of your questions.   Here's a case where I can't really "teach you to fish" using the python API but I might be able to offer you a fish or two for today.

 

1. You seem to be defining a task with a digital trigger but without a hardware clock and buffer for sampling.  Most tasks that want to start off a hardware-precise trigger will also want hardware-precise sample timing.   In LabVIEW, the standard function we call is "DAQmx Timing" where we define either continuous or finite sampling, a sample rate, and a buffer size.

    I don't know your particular board, but it's possible that start triggers are only supported for hardware-clocked tasks.   (It's also possible that triggering simply isn't supported at all for digital input, I couldn't clearly tell from a quick look at the spec sheet.)

 

2. I notice that you use single quotes to delimit your DI channel name while using double quotes to delimit your trigger signal name.   I suspect one of these is wrong.

 

3. It's likely that if your board *does* support DI triggering, the trigger signal needs to be wired to a PFI pin (and identified that way).  A likely syntax: "/Dev1/PFI0"    Note the leading '/' (forward slash) character.  This is needed when referencing *terminals*.  (In contrast, it's not needed or allowed when referencing *channels* as in "Dev1/port0/line0".   Why?  I have no idea.  Just eat the fish.  Smiley Wink )

 

4.  On at least some boards (apparently including yours), an analog signal that's going to be used for triggering must be included in the task.   Typically that is *not* a restriction for digital tasks.  A task can be triggered by a digital signal that isn't being acquired in the task, though one must refer to the trigger signal by its PFI terminal name.

 

Hopefully some of this helps in the short term, maybe someone else can chime in with pointers to better sources of python-related info for the longer term.

 

 

-Kevin P

 

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 3
(3,997 Views)