Jump to content
  • 0

Receive ULError.BAD_DEV_HANDLE When Connect to DAQ


Ricky Ooi

Question

I have 2 DAQ devices, which are USB-1808 and USB-QUAD08. By using Python, I first obtained the device through get_daq_device_inventory function. From the function, I obtained two devices. After that, I using looping method to create DAQ Device object using DAQDevice class. After DAQ Device object is created, I called connect() function. The moment I called this function, I got error of ULError.BAD_DEV_HANDLE. I also tried other function like get_descriptor(), the same error is prompted as well. Can I know what is the problem of this?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Hello,

The error typically occurs with an incorrect index into the device inventory. For example:

daq_device = DaqDevice(devices[x]) where is x is not a valid device.

Try something like this: (2x_Device_Discovery.py)

   try:
        # Get descriptors for all of the available DAQ devices.
        devices = get_daq_device_inventory(InterfaceType.USB)
        number_of_devices = len(devices)
        if number_of_devices == 0:
            raise Exception('Error: No DAQ devices found')

        print('Found', number_of_devices, 'DAQ device(s):')

        device_to_show = "USB-1808"
        for i in range(number_of_devices):
            board_name = devices[i].product_name
            if device_to_show in board_name:
                print("{0} found\n".format(board_name))
                print('  ', devices[i].product_name, ' (', devices[i].unique_id, ')', sep='')


                # Create the DAQ device object associated with the specified descriptor index.
                daq_device = DaqDevice(devices[i])

                # Establish a connection to the DAQ device.
                descriptor = daq_device.get_descriptor()
                print('\nConnecting to', descriptor.dev_string, '- please wait...')
                daq_device.connect()
                daq_device.flash_led(5)

        device_to_show = "USB-QUAD08"
        for i in range(number_of_devices):
            board_name = devices[i].product_name
            if device_to_show in board_name:
                print("{0} found\n".format(board_name))
                print('  ', devices[i].product_name, ' (', devices[i].unique_id, ')', sep='')


                # Create the DAQ device object associated with the specified descriptor index.
                daq_device2 = DaqDevice(devices[i])

                # Establish a connection to the DAQ device.
                descriptor = daq_device.get_descriptor()
                print('\nConnecting to', descriptor.dev_string, '- please wait...')
                daq_device2.connect()
                daq_device2.flash_led(5)

    except RuntimeError as error:
        print('\n', error)

 

Link to comment
Share on other sites

  • 0

I modified the test program to use DaqDevice twice and did not get the error. However, I recommend maintaining a device object for both the 1808 and the QUAD09 assuming both are used. Instead of different named objects, use an array.

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from __future__ import print_function
from sys import stdout

from uldaq import (get_daq_device_inventory, DaqDevice, InterfaceType,
                   AInScanFlag, ScanStatus, ScanOption, Range,
                   create_float_buffer, AiInputMode)


def main():
    """Analog input scan example."""
    daq_device = None

    #daq_device = None
    daq_device = []
    descriptor = 0

    try:
        # Get descriptors for all of the available DAQ devices.
        devices = get_daq_device_inventory(InterfaceType.USB)
        number_of_devices = len(devices)
        if number_of_devices == 0:
            raise Exception('Error: No DAQ devices found')

        print('Found', number_of_devices, 'DAQ device(s):')

        device_to_show = "USB-1808"
        for i in range(number_of_devices):
            board_name = devices[i].product_name
            if device_to_show in board_name:
                print("{0} found\n".format(board_name))
                print('  ', devices[i].product_name, ' (', devices[i].unique_id, ')', sep='')


                # Create the DAQ device object associated with the specified descriptor index.
                daq_device.append(DaqDevice(devices[i]))


                # Establish a connection to the DAQ device.
                descriptor = daq_device[0].get_descriptor()
                print('\nConnecting to', descriptor.dev_string, '- please wait...')
                daq_device[0].connect()
                daq_device[0].flash_led(5)

        device_to_show = "USB-2408"
        for i in range(number_of_devices):
            board_name = devices[i].product_name
            if device_to_show in board_name:
                print("{0} found\n".format(board_name))
                print('  ', devices[i].product_name, ' (', devices[i].unique_id, ')', sep='')


                # Create the DAQ device object associated with the specified descriptor index.
                daq_device.append(DaqDevice(devices[i]))

                # Establish a connection to the DAQ device.
                descriptor = daq_device[1].get_descriptor()
                print('\nConnecting to', descriptor.dev_string, '- please wait...')
                daq_device[1].connect()
                daq_device[1].flash_led(5)

    except RuntimeError as error:
        print('\n', error)

    finally:
        if daq_device:
            # Stop the acquisition if it is still running.

            if daq_device[0].is_connected():
                daq_device[0].disconnect()
                print('disconnect device 1')
            daq_device[0].release()

            if daq_device[1].is_connected():
                daq_device[1].disconnect()
                print('disconnect device 2')
            daq_device[1].release()

def reset_cursor():
    """Reset the cursor in the terminal window."""
    stdout.write('\033[1;1H')


def clear_eol():
    """Clear all characters to the end of the line."""
    stdout.write('\x1b[2K')


if __name__ == '__main__':
    main()
 

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...