Jump to content
  • 0

How to stop an acqusition using TriggerEvent.STOP (Python and USB1808X)


Julien S

Question

Hi everyone,

I'm trying to write a simple piece of python code using github examples but i'm facing some issues while i try to stop an acquisition with ul.daq_in_scan() function.

My goal is fairly simple (i guess): i want to scan the 8 analog channel at maximal rate (one point each 5µs) and stop the acquisition either by using a TTL signal, a HIGH to LOW hardware transition (using arduino for instance) or even after the completion of 500 measurements for each channel.

Here the code i use (i volontary skip the displaying value part).

from __future__ import absolute_import, division, print_function
from builtins import *  # @UnusedWildImport

from ctypes import cast, POINTER, c_ushort

import time

from mcculw import ul
from mcculw.enums import (ScanOptions, Status, FunctionType, ChannelType,
                          ULRange, DigitalPortType, TriggerSensitivity,
                          TriggerEvent, TriggerSource, InterfaceType)
from mcculw.ul import ULError
from mcculw.device_info import DaqDeviceInfo

try:
    from ui_examples_util import UIExample, show_ul_error
except ImportError:
    from .ui_examples_util import UIExample, show_ul_error


def ADCScanFunction():

        use_device_detection = True
        board_num = 0

        chan_list = []
        chan_type_list = []
        gain_list = []
        num_chans = 8

        try:
            if use_device_detection:
                ul.ignore_instacal()
                devices = ul.get_daq_device_inventory(InterfaceType.ANY)
                ul.create_daq_device(board_num, devices[0])

            device_info = DaqDeviceInfo(board_num)
            
            if device_info.supports_daq_input:

                for i in range(0,8):
                    chan_list.append(i)
                    chan_type_list.append(ChannelType.ANALOG_SE)
                    gain_list.append(ULRange.UNI5VOLTS)
                    
                chan_list.append(0)
                chan_type_list.append(ChannelType.CTR16)
                gain_list.append(ULRange.NOTUSED)
                    
                    
        except:
            print('ok')
            
            
            
        rate = 200000
        points_per_channel = 500
        total_count = points_per_channel * (num_chans)
        scan_options = (ScanOptions.FOREGROUND | ScanOptions.EXTTRIGGER)
        # scan_options = (ScanOptions.BACKGROUND |
        #                 ScanOptions.CONTINUOUS | ScanOptions.EXTTRIGGER)

        # Allocate a buffer for the scan
        memhandle = ul.win_buf_alloc_32(total_count)

        #Set the start trigger settings
        ul.daq_set_trigger(board_num, TriggerSource.EXTTTL,
                          TriggerSensitivity.RISING_EDGE,
                          chan_list[-1], chan_type_list[-1],
                          gain_list[-1], 5, 0, TriggerEvent.START)
        
        ul.daq_set_trigger(board_num, TriggerSource.EXTTTL,
                          TriggerSensitivity.ABOVE_LEVEL,
                          chan_list[-1], chan_type_list[-1],
                          gain_list[-1], 5, 0, TriggerEvent.STOP)
        

        c = chan_list[0:8]
        # Run the scan
        ul.daq_in_scan(board_num, chan_list[0:8], chan_type_list[0:8],
                        gain_list[0:8], num_chans, rate, 0, total_count,
                        memhandle, scan_options)

When i use this, i have the following error:

Quote

    raise ULError(errcode)

ULError: Error 1015: Invalid trigger event specified.

I'm kind of lost and i'm affraid i don't understand how the TriggerEvent.STOP would work (and github examples are not very detailled in term of stopping an acquisition).

if someone could guide me on how to stop an acquisition with my previous condition (TTL, 5V to 0V, or after 500 points) that would be great !

Thank you to all those who will take the time to help me !

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hello @Julien S.

According to the UL Help (https://www.mccdaq.com/pdfs/manuals/Mcculw_WebHelp/ULStart.htm), the USB-1808 Series does not support a DAQ Triggering 'STOP_EVENT', only a 'START_EVENT'.

image.png

 

The provided UL Python example, DaqInScan01.py, scans a set # of samples for each channel specified and then stops the acquisition.  The DaqInScan02.py example scans continuously until the user presses the STOP button. 

If you scan continuously, then you can have a STOP button in your application or connect the TTL signal to a digital bit and have some logic code to detect a level change, before calling ul.stop_background().

Regards,

Fausto

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...