Ejemplo n.º 1
0
    def _get_extended_error_info(self):
        r'''_get_extended_error_info

        Returns detailed information about the last error that occurred in the
        current thread during a call to one of the NI-ModInst methods. When
        one of the other methods returns a negative value as its return value,
        immediately call this method to get detailed information about the
        error. Because error information is stored on a thread-by-thread basis,
        be sure to call this method in the same thread that called the
        method that returned an error. The extended error information is
        returned as a string. To find out the length of the error information
        string before you allocate a buffer for it, call this method and pass
        0 as the errorInfoBufferSize parameter or NULL as the errorInfo
        parameter. When you do this, the method returns the size of the buffer
        required to hold the error information string as its return value. You
        can then allocate an appropriately sized string character buffer and
        call this method again.

        Returns:
            error_info (str): The character buffer into which the error information string is copied.

        '''
        error_info_buffer_size_ctype = _visatype.ViInt32()  # case S170
        error_info_ctype = None  # case C050
        error_code = self._library.niModInst_GetExtendedErrorInfo(error_info_buffer_size_ctype, error_info_ctype)
        errors.handle_error(self, error_code, ignore_warnings=True, is_error_handling=True)
        error_info_buffer_size_ctype = _visatype.ViInt32(error_code)  # case S180
        error_info_ctype = (_visatype.ViChar * error_info_buffer_size_ctype.value)()  # case C060
        error_code = self._library.niModInst_GetExtendedErrorInfo(error_info_buffer_size_ctype, error_info_ctype)
        errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=True)
        return error_info_ctype.value.decode(self._encoding)
Ejemplo n.º 2
0
    def _get_installed_device_attribute_vi_string(self, index, attribute_id):
        r'''_get_installed_device_attribute_vi_string

        Returns a string property specified by the attributeID parameter for a
        device specified by the handle and index parameters. The handle
        parameter is expected to be a valid handle returned by
        _open_installed_devices_session. Therefore, it acts as a handle
        to a list of installed devices. The index parameter specifies for which
        device in the list you want the property. To find out the length of the
        device name string before you allocate a buffer for it, simply call this
        method and pass 0 as the attributeValueBufferSize parameter or NULL as
        the attributeValue parameter. When you do this, the method returns the
        size of the buffer required to hold the property value string as its
        return value. You can then allocate an appropriately sized character
        buffer and call this method again.

        Args:
            index (int): A zero-based index that specifies the device for which you want the
                property. This index parameter should be between 0 and (deviceCount -
                1), inclusive, where deviceCount is the number of installed devices
                returned by _open_installed_devices_session.

            attribute_id (int): The ID of the string property you want to query. Valid Values
                device_name--the name of the device, which can be used
                to open an instrument driver session for that device
                device_model--the model of the device (for example, NI
                PXI-5122) serial_number--the serial number of the
                device


        Returns:
            attribute_value (str): The character buffer into which the property value string is copied.

        '''
        handle_ctype = _visatype.ViSession(self._handle)  # case S110
        index_ctype = _visatype.ViInt32(index)  # case S150
        attribute_id_ctype = _visatype.ViInt32(attribute_id)  # case S150
        attribute_value_buffer_size_ctype = _visatype.ViInt32()  # case S170
        attribute_value_ctype = None  # case C050
        error_code = self._library.niModInst_GetInstalledDeviceAttributeViString(
            handle_ctype, index_ctype, attribute_id_ctype,
            attribute_value_buffer_size_ctype, attribute_value_ctype)
        errors.handle_error(self,
                            error_code,
                            ignore_warnings=True,
                            is_error_handling=False)
        attribute_value_buffer_size_ctype = _visatype.ViInt32(
            error_code)  # case S180
        attribute_value_ctype = (
            _visatype.ViChar *
            attribute_value_buffer_size_ctype.value)()  # case C060
        error_code = self._library.niModInst_GetInstalledDeviceAttributeViString(
            handle_ctype, index_ctype, attribute_id_ctype,
            attribute_value_buffer_size_ctype, attribute_value_ctype)
        errors.handle_error(self,
                            error_code,
                            ignore_warnings=False,
                            is_error_handling=False)
        return attribute_value_ctype.value.decode(self._encoding)
Ejemplo n.º 3
0
    def _get_installed_device_attribute_vi_int32(self, index, attribute_id):
        r'''_get_installed_device_attribute_vi_int32

        Returns an integer property specified by the attributeID parameter for
        a device specified by the handle and index parameters. The handle
        parameter is expected to be a valid handle returned by
        _open_installed_devices_session. It therefore acts as a handle to
        a list of installed devices. The index parameter specifies the device in
        the list for which you want the property.

        Args:
            index (int): A zero-based index that specifies the device for which you want the
                property. This index parameter should be between 0 and (deviceCount -
                1), inclusive, where deviceCount is the number of installed devices
                returned by _open_installed_devices_session.

            attribute_id (int): The ID of the integer property you want to query. Valid Values Slot
                Number--the slot (for example, in a PXI chassis) in which the device is
                installed. This property can only be queried for PXI devices installed
                in a chassis that has been properly identified in MAX. Chassis
                Number--the number of the chassis in which the device is installed. This
                property can only be queried for PXI devices installed in a chassis
                that has been properly identified in MAX. Bus Number--the bus on which
                the device has been enumerated. Socket Number--the socket number on
                which the device has been enumerated. Notes The bus number and socket
                number can be used to form a VISA resource string for this device, of
                the form "PXI::::INSTR". Traditional NI-DAQ devices do not support the
                chassis number, bus number, and socket number properties.


        Returns:
            attribute_value (int): A pointer to a signed 32-bit integer variable that receives the value of
                the requested property.

        '''
        handle_ctype = _visatype.ViSession(self._handle)  # case S110
        index_ctype = _visatype.ViInt32(index)  # case S150
        attribute_id_ctype = _visatype.ViInt32(attribute_id)  # case S150
        attribute_value_ctype = _visatype.ViInt32()  # case S220
        error_code = self._library.niModInst_GetInstalledDeviceAttributeViInt32(
            handle_ctype, index_ctype, attribute_id_ctype,
            None if attribute_value_ctype is None else
            (ctypes.pointer(attribute_value_ctype)))
        errors.handle_error(self,
                            error_code,
                            ignore_warnings=False,
                            is_error_handling=False)
        return int(attribute_value_ctype.value)
Ejemplo n.º 4
0
    def _get_error_description(self, error_code):
        '''_get_error_description

        Returns the error description.
        '''
        # We hand-maintain the code that calls into self._library rather than leverage code-generation
        # because niModInst_GetExtendedErrorInfo() does not properly do the IVI-dance.
        # See https://github.com/ni/nimi-python/issues/166
        error_info_buffer_size_ctype = _visatype.ViInt32()  # case S170
        error_info_ctype = None  # case C050
        error_code = self._library.niModInst_GetExtendedErrorInfo(error_info_buffer_size_ctype, error_info_ctype)
        if error_code <= 0:
            return "Failed to retrieve error description."
        error_info_buffer_size_ctype = _visatype.ViInt32(error_code)  # case S180
        error_info_ctype = (_visatype.ViChar * error_info_buffer_size_ctype.value)()  # case C060
        # Note we don't look at the return value. This is intentional as niModInst returns the
        # original error code rather than 0 (VI_SUCCESS).
        self._library.niModInst_GetExtendedErrorInfo(error_info_buffer_size_ctype, error_info_ctype)
        return error_info_ctype.value.decode("ascii")
Ejemplo n.º 5
0
    def _open_installed_devices_session(self, driver):
        r'''_open_installed_devices_session

        Creates a handle to a list of installed devices supported by the
        specified driver. Call this method and pass in the name of an NI
        instrument driver, such as "NI-SCOPE". This method
        searches the system and constructs a list of all the installed devices
        that are supported by that driver, and then returns both a handle to
        this list and the number of devices found. The handle is used with other
        methods to query for properties such as device name and model, and to
        safely discard the list when finished. Note This handle reflects the
        system state when the handle is created (that is, when you call this
        method. If you remove devices from the system or rename them in
        Measurement & Automation Explorer (MAX), this handle may not refer to an
        accurate list of devices. You should destroy the handle using
        _close_installed_devices_session and create a new handle using
        this method.

        Args:
            driver (str): A string specifying the driver whose supported devices you want to find.
                This string is not case-sensitive. Some examples are: NI-SCOPE niScope
                NI-FGEN niFgen NI-HSDIO niHSDIO NI-DMM niDMM NI-SWITCH niSwitch Note If
                you use the empty string for this parameter, NI-ModInst creates a list
                of all Modular Instruments devices installed in the system.


        Returns:
            handle (int): A pointer to a ViSession variable that receives the value of the
                NI-ModInst session handle. This value acts as a handle to the list of
                installed devices and is used in other NI-ModInst methods.

            device_count (int): A pointer to an integer variable that receives the number of devices
                found in the system that are supported by the driver specified in the
                driver parameter.

        '''
        driver_ctype = ctypes.create_string_buffer(
            driver.encode(self._encoding))  # case C020
        handle_ctype = _visatype.ViSession()  # case S220
        device_count_ctype = _visatype.ViInt32()  # case S220
        error_code = self._library.niModInst_OpenInstalledDevicesSession(
            driver_ctype, None if handle_ctype is None else
            (ctypes.pointer(handle_ctype)),
            None if device_count_ctype is None else
            (ctypes.pointer(device_count_ctype)))
        errors.handle_error(self,
                            error_code,
                            ignore_warnings=False,
                            is_error_handling=False)
        return int(handle_ctype.value), int(device_count_ctype.value)