Beispiel #1
0
    def _get_installed_device_attribute_vi_string(self, index, attribute_id):
        '''_get_installed_device_attribute_vi_string

        Returns a string attribute 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 attribute. To find out the length of the
        device name string before you allocate a buffer for it, simply call this
        function and pass 0 as the attributeValueBufferSize parameter or NULL as
        the attributeValue parameter. When you do this, the function returns the
        size of the buffer required to hold the attribute value string as its
        return value. You can then allocate an appropriately sized character
        buffer and call this function again.

        Args:
            index (int): A zero-based index that specifies the device for which you want the
                attribute. 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 attribute 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
            attribute_value_buffer_size (int): The size of the buffer allocated and passed in as the attributeValue
                parameter. The buffer should be large enough to hold the attribute value
                string (including a NULL terminating character). Refer to the
                Description section for information on how to determine the exact buffer
                size required.
        '''
        handle_ctype = visatype.ViSession(self._handle)  # case 1
        index_ctype = visatype.ViInt32(index)  # case 8
        attribute_id_ctype = visatype.ViInt32(attribute_id)  # case 8
        attribute_value_buffer_size_ctype = visatype.ViInt32()  # case 6
        attribute_value_ctype = None  # case 11
        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
        )  # TODO(marcoskirsch): use get_ctype_variable_declaration_snippet()
        attribute_value_ctype = (
            visatype.ViChar * attribute_value_buffer_size_ctype.value
        )()  # TODO(marcoskirsch): use get_ctype_variable_declaration_snippet()
        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)
Beispiel #2
0
    def _get_extended_error_info(self):
        '''_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 functions. When
        one of the other functions returns a negative value as its return value,
        immediately call this function to get detailed information about the
        error. Because error information is stored on a thread-by-thread basis,
        be sure to call this function in the same thread that called the
        function 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 function and pass
        0 as the errorInfoBufferSize parameter or NULL as the errorInfo
        parameter. When you do this, the function 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 function again.

        Args:
            error_info_buffer_size (int): The size of the buffer allocated and passed in as the errorInfo
                parameter. The buffer should be large enough to hold the errorInfo
                string (including a NULL terminating character). The size of the buffer
                allocated and passed in as the errorInfo parameter. The buffer should be
                large enough to hold the errorInfo string (including a NULL terminating
                character). Refer to the function help to find out how to determine the
                exact buffer size required.
        '''
        error_info_buffer_size_ctype = visatype.ViInt32()  # case 6
        error_info_ctype = None  # case 11
        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
        )  # TODO(marcoskirsch): use get_ctype_variable_declaration_snippet()
        error_info_ctype = (
            visatype.ViChar * error_info_buffer_size_ctype.value
        )()  # TODO(marcoskirsch): use get_ctype_variable_declaration_snippet()
        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)
Beispiel #3
0
    def _get_installed_device_attribute_vi_int32(self, index, attribute_id):
        '''_get_installed_device_attribute_vi_int32

        Returns an integer attribute 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 attribute.

        Args:
            index (int): A zero-based index that specifies the device for which you want the
                attribute. 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 attribute you want to query. Valid Values Slot
                Number--the slot (for example, in a PXI chassis) in which the device is
                installed. This attribute 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
                attribute 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 attributes.

        Returns:
            attribute_value (int): A pointer to a signed 32-bit integer variable that receives the value of
                the requested attribute.
        '''
        handle_ctype = visatype.ViSession(self._handle)  # case 1
        index_ctype = visatype.ViInt32(index)  # case 8
        attribute_id_ctype = visatype.ViInt32(attribute_id)  # case 8
        attribute_value_ctype = visatype.ViInt32()  # case 13
        error_code = self._library.niModInst_GetInstalledDeviceAttributeViInt32(
            handle_ctype, index_ctype, attribute_id_ctype,
            ctypes.pointer(attribute_value_ctype))
        errors.handle_error(self,
                            error_code,
                            ignore_warnings=False,
                            is_error_handling=False)
        return int(attribute_value_ctype.value)
Beispiel #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()
        error_info_ctype = None
        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)
        error_info_ctype = ctypes.create_string_buffer(
            error_info_buffer_size_ctype.value)
        # 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")
Beispiel #5
0
    def _open_installed_devices_session(self, driver):
        '''_open_installed_devices_session

        Creates a handle to a list of installed devices supported by the
        specified driver. Call this function and pass in the name of a National
        Instruments instrument driver, such as "NI-SCOPE". This function
        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
        functions to query for attributes 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
        function. 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 function.

        Args:
            driver (string): 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 functions.
            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 3
        handle_ctype = visatype.ViSession()  # case 13
        device_count_ctype = visatype.ViInt32()  # case 13
        error_code = self._library.niModInst_OpenInstalledDevicesSession(
            driver_ctype, ctypes.pointer(handle_ctype),
            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)