Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB-6001 register_signal_event not supported (Python)

Solved!
Go to solution

Hi,

 

I'm working with a NI USB-6001 with Python (nidaqmx-python) and want to use a digital input as trigger source to start acquisition. I tried to register_signal_event to detect a change in signal. However, I got an error signal events are not supported by my device. I was surprised since the device have a counter. I just want to know if this device really does not support signal events or I'm doing something wrong in my implementation.  See below the snip of the code and the error.

 

Code:

 

def sync_in_trigger(device, port, line, timeout = 1):
    # Timeout - time allowed to wait for trigger in seconds
    global sync_in_status
    global sync_in_fail
    sync_in_status = False # Status of the trigger in signal
    sync_in_fail = False # Timeout status
    name = f'{device}/{port}/{line}'

    with nidaqmx.Task() as task:
        task.di_channels.add_di_chan(name)
        task.register_signal_event(constants.Signal.CHANGE_DETECTION_EVENT, sync_in_callback)
        print('Waiting for trigger...')
        start = default_timer()
        task.start()
        while not sync_in_status:
            elapsed = default_timer() - start
            if elapsed > timeout:
                sync_in_fail = True
                print('Timed Out! Trigger not detected!')
                break
            sleeper(0.5) # Adjust frequency if necessary

 

 

Error:

ni_triggers.sync_in_trigger('Dev1','port1','line1')
Traceback (most recent call last):

File "<ipython-input-19-6cd667112031>", line 1, in <module>
ni_triggers.sync_in_trigger('Dev1','port1','line1')

File "E:\Dropbox\Controller\ni_triggers.py", line 113, in sync_in_trigger

File "C:\ProgramData\Anaconda3\lib\site-packages\nidaqmx\task.py", line 951, in register_signal_event
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)

0 Kudos
Message 1 of 7
(1,974 Views)

Hi,

 

Based on specifications of NI USB 6001: https://www.ni.com/pdf/manuals/374369a.pdf

I believe it do support a digital input trigger source, did you try to configure it with another trigger input which PFl 0 (port 2, line 0)   wait for an edge before starting the acquisition ?

 

By the way, I found this link might be useful as it mentioned about using software trigger instead of using the digital input PFl line even though it discussing about NI 6002 but maybe software trigger could work on NI 6001 too:

https://stackoverflow.com/questions/53356449/triggering-an-output-task-with-nidaqmx

 

 

Message 2 of 7
(1,910 Views)
Solution
Accepted by JocaHC

Your device does not support change detection or any other hardware-driven sampling of digital inputs.  The counter can only count up, it can't do any of the things the more versatile counters on more expensive DAQ boards can do (freq measurement, quadrature decode, pulse train generation, etc.)

 

You'll probably have to do your polling and response in software.

 

 

-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.
Message 3 of 7
(1,896 Views)

That a bummer. Anyway, I already have a solution for polling in software, not ideal but works. I'll look into the solution that WaiLee provided, maybe will make my implementation better.

 

Thank you all.

0 Kudos
Message 4 of 7
(1,882 Views)

I was wondering if you could share what you did?  I have a usb-6001 too.

0 Kudos
Message 5 of 7
(443 Views)

Sure. Not a very pretty code but worked for my user case.

 

import nidaqmx
from nidaqmx import constants
from nidaqmx import stream_writers 
import time
import numpy as np
from timeit import default_timer

def sleeper(delay): # Sleep function - delay in seconds
    if delay <= 0.1: # Delay cutoff - adjust is necessary for each machine/OS
        start = default_timer()
        while(default_timer()<start+delay):
            continue
    else:
        time.sleep(delay) # Not very reliable in very short duration - machine/OS dependent (Linux > Windows)
def sync_in_callback(task_idx, signal_type, callback_data):  
    global sync_in_status
    if sync_in_fail:
        return 0    
    else:
        print(f'{task_idx}')
        print(f'{signal_type}')
        print(f'{callback_data}')
        sync_in_status = True
    return 0

def sync_in_trigger(device, port, line, timeout = 1):
    # Timeout - time allowed to wait for trigger in seconds
    global sync_in_status
    global sync_in_fail
    sync_in_status = False # Status of the trigger in signal
    sync_in_fail = False # Timeout status
    name = f'{device}/{port}/{line}'

    with nidaqmx.Task() as task:
        task.di_channels.add_di_chan(name)
        task.register_signal_event(nidaqmx.constants.Signal.CHANGE_DETECTION_EVENT, sync_in_callback)
        print('Waiting for trigger...')
        start = default_timer()
        task.start()
        while not sync_in_status:
            elapsed = default_timer() - start
            if elapsed > timeout:
                sync_in_fail = True
                print('Timed Out! Trigger not detected!')
                break
            sleeper(0.5) # Adjust frequency if necessary

 

0 Kudos
Message 6 of 7
(432 Views)

Thank you for your help!

0 Kudos
Message 7 of 7
(424 Views)