Exemplo n.º 1
0
def _read_ctr_time(task_handle,
                   high_time,
                   low_time,
                   num_samps_per_chan,
                   timeout,
                   interleaved=FillMode.GROUP_BY_CHANNEL):
    samps_per_chan_read = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxReadCtrTime
    cfunc.argtypes = [
        lib_importer.task_handle, ctypes.c_int, ctypes.c_double, ctypes.c_int,
        wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
        wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
        ctypes.c_uint,
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(c_bool32)
    ]

    error_code = cfunc(task_handle, num_samps_per_chan, timeout,
                       interleaved.value, high_time, low_time,
                       numpy.prod(high_time.shape),
                       ctypes.byref(samps_per_chan_read), None)
    check_for_error(error_code)

    return samps_per_chan_read.value
Exemplo n.º 2
0
def _read_ctr_freq(task_handle,
                   freq,
                   duty_cycle,
                   num_samps_per_chan,
                   timeout,
                   interleaved=FillMode.GROUP_BY_CHANNEL):
    samps_per_chan_read = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxReadCtrFreq
    if cfunc.argtypes is None:
        with cfunc.arglock:
            if cfunc.argtypes is None:
                cfunc.argtypes = [
                    lib_importer.task_handle, ctypes.c_int, ctypes.c_double,
                    ctypes.c_int,
                    wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
                    wrapped_ndpointer(dtype=numpy.float64,
                                      flags=('C', 'W')), ctypes.c_uint,
                    ctypes.POINTER(ctypes.c_int),
                    ctypes.POINTER(c_bool32)
                ]

    error_code = cfunc(task_handle, num_samps_per_chan, timeout,
                       interleaved.value, freq, duty_cycle,
                       numpy.prod(freq.shape),
                       ctypes.byref(samps_per_chan_read), None)
    check_for_error(error_code, samps_per_chan_read=samps_per_chan_read.value)

    return samps_per_chan_read.value
Exemplo n.º 3
0
    def create_polynomial_scale(scale_name,
                                forward_coeffs,
                                reverse_coeffs,
                                pre_scaled_units=UnitsPreScaled.VOLTS,
                                scaled_units=None):
        """
        Creates a custom scale that uses an nth order polynomial
        equation. NI-DAQmx requires both a polynomial to convert pre-
        scaled values to scaled values (forward) and a polynomial to
        convert scaled values to pre-scaled values (reverse). If you
        only know one set of coefficients, use the DAQmx Compute Reverse
        Polynomial Coefficients function to generate the other set.

        Args:
            scale_name (str): Specifies the name of the scale to create.
            forward_coeffs (List[float]): Is an list of coefficients for
                the polynomial that converts pre-scaled values to scaled
                values. Each element of the list corresponds to a term
                of the equation.
            reverse_coeffs (List[float]): Is an list of coefficients for
                the polynomial that converts scaled values to pre-scaled
                values. Each element of the list corresponds to a term
                of the equation.
            pre_scaled_units (Optional[nidaqmx.constants.UnitsPreScaled]):
                Is the units of the values to scale.
            scaled_units (Optional[str]): Is the units to use for the
                scaled value. You can use an arbitrary string. NI-DAQmx
                uses the units to label a graph or chart.
        Returns:
            nidaqmx.scale.Scale: 
            
            Indicates an object that represents the created custom scale.
        """
        scale = Scale(scale_name)

        if forward_coeffs is None:
            forward_coeffs = []

        if reverse_coeffs is None:
            reverse_coeffs = []

        forward_coeffs = numpy.float64(forward_coeffs)
        reverse_coeffs = numpy.float64(reverse_coeffs)

        cfunc = lib_importer.windll.DAQmxCreatePolynomialScale
        cfunc.argtypes = [
            ctypes_byte_str,
            wrapped_ndpointer(dtype=numpy.float64,
                              flags=('C', 'W')), ctypes.c_uint,
            wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
            ctypes.c_uint, ctypes.c_int, ctypes_byte_str
        ]

        error_code = cfunc(scale_name, forward_coeffs,
                           len(forward_coeffs), reverse_coeffs,
                           len(reverse_coeffs), pre_scaled_units.value,
                           scaled_units)
        check_for_error(error_code)

        return scale
Exemplo n.º 4
0
def _write_ctr_freq(task_handle,
                    freq,
                    duty_cycle,
                    num_samps_per_chan,
                    auto_start,
                    timeout,
                    data_layout=FillMode.GROUP_BY_CHANNEL):
    num_samps_per_chan_written = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxWriteCtrFreq
    cfunc.argtypes = [
        lib_importer.task_handle, ctypes.c_int, c_bool32, ctypes.c_double,
        ctypes.c_int,
        wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
        wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(c_bool32)
    ]

    error_code = cfunc(task_handle, num_samps_per_chan, auto_start, timeout,
                       data_layout.value, freq, duty_cycle,
                       ctypes.byref(num_samps_per_chan_written), None)
    check_for_error(error_code)

    return num_samps_per_chan_written.value
Exemplo n.º 5
0
def _write_ctr_ticks(task_handle,
                     high_tick,
                     low_tick,
                     num_samps_per_chan,
                     auto_start,
                     timeout,
                     data_layout=FillMode.GROUP_BY_CHANNEL):
    num_samps_per_chan_written = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxWriteCtrTicks
    if cfunc.argtypes is None:
        with cfunc.arglock:
            if cfunc.argtypes is None:
                cfunc.argtypes = [
                    lib_importer.task_handle, ctypes.c_int, c_bool32,
                    ctypes.c_double, ctypes.c_int,
                    wrapped_ndpointer(dtype=numpy.uint32, flags=('C', 'W')),
                    wrapped_ndpointer(dtype=numpy.uint32, flags=('C', 'W')),
                    ctypes.POINTER(ctypes.c_int),
                    ctypes.POINTER(c_bool32)
                ]

    error_code = cfunc(task_handle, num_samps_per_chan, auto_start, timeout,
                       data_layout.value, high_tick, low_tick,
                       ctypes.byref(num_samps_per_chan_written), None)
    check_for_error(error_code)

    return num_samps_per_chan_written.value
Exemplo n.º 6
0
    def create_table_scale(
            scale_name, prescaled_vals, scaled_vals,
            pre_scaled_units=UnitsPreScaled.VOLTS, scaled_units=None):
        """
        Creates a custom scale that maps an list of pre-scaled values to
        an list of corresponding scaled values. NI-DAQmx applies linear
        interpolation to values that fall between the values in the
        table. Read operations clip scaled samples that are outside the
        maximum and minimum scaled values found in the table. Write
        operations generate errors for samples that are outside the
        minimum and maximum scaled values found in the table.

        Args:
            scale_name (str): Specifies the name of the scale to create.
            prescaled_vals (List[float]): Is the list of pre-scaled
                values that map to the values in "scaled_vals".
            scaled_vals (List[float]): Is the list of scaled values that
                map to the values in "prescaled_vals".
            pre_scaled_units (Optional[nidaqmx.constants.UnitsPreScaled]):
                Is the units of the values to scale.
            scaled_units (Optional[str]): Is the units to use for the
                scaled value. You can use an arbitrary string. NI-DAQmx
                uses the units to label a graph or chart.
        Returns:
            nidaqmx.scale.Scale: 
            
            Indicates an object that represents the created custom scale.
        """
        scale = Scale(scale_name)

        if prescaled_vals is None:
            prescaled_vals = []

        if scaled_vals is None:
            scaled_vals = []

        prescaled_vals = numpy.float64(prescaled_vals)
        scaled_vals = numpy.float64(scaled_vals)

        cfunc = lib_importer.windll.DAQmxCreateTableScale
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C', 'W')),
                        ctypes.c_uint,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C', 'W')),
                        ctypes.c_uint, ctypes.c_int, ctypes_byte_str]

        error_code = cfunc(
            scale_name, prescaled_vals, len(prescaled_vals), scaled_vals,
            len(scaled_vals), pre_scaled_units.value, scaled_units)
        check_for_error(error_code)

        return scale
Exemplo n.º 7
0
    def cfg_watchdog_ao_expir_states(self, expiration_states):
        """
        Configures the expiration states for an analog watchdog timer task.

        Args:
            expiration_states
                (List[nidaqmx.system.watchdog.AOExpirationState]):
                Contains the states to which to set analog physical channels
                when the watchdog timer expires. Each element of the list
                contains an analog physical channel name, the corresponding
                expiration state, and the output type for that analog
                physical channel. The units of "expiration state" must be
                specified in volts for an analog output voltage expiration
                state, or amps for an analog output current expiration state.

                physical_channel (str): Specifies the analog output channel to
                    modify. You cannot modify dedicated analog input lines.
                expiration_state (float): Specifies the value to set the
                    channel to upon expiration.
                output_type (nidaqmx.constants.WatchdogAOExpirState):
                    Specifies the output type of the physical channel.
        Returns:
            List[nidaqmx.system._watchdog_modules.expiration_state.ExpirationState]:

            Indicates the list of objects representing the configured
            expiration states.
        """
        channel_names = flatten_channel_string(
            [e.physical_channel for e in expiration_states])
        expir_state = numpy.float64(
            [e.expiration_state for e in expiration_states])
        output_type = numpy.int32(
            [e.output_type.value for e in expiration_states])

        cfunc = lib_importer.windll.DAQmxCfgWatchdogAOExpirStates
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        lib_importer.task_handle, ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C', 'W')),
                        wrapped_ndpointer(dtype=numpy.int32, flags=('C', 'W')),
                        ctypes.c_uint
                    ]

        error_code = cfunc(self._handle, channel_names, expir_state,
                           output_type, len(expiration_states))
        check_for_error(error_code)

        return [
            ExpirationState(self._handle, e.physical_channel)
            for e in expiration_states
        ]
Exemplo n.º 8
0
    def get_analog_power_up_states_with_output_type(self, physical_channels):
        """
        Gets the power up states for analog physical channels.

        Args:
            physical_channels (List[str]): Indicates the physical
                channels that were modified.
        Returns:
            power_up_states (List[nidaqmx.types.AOPowerUpState]):

            Contains the physical channels and power up states set. Each
            element of the list contains a physical channel and the
            power up state set for that physical channel.

            - physical_channel (str): Specifies the physical channel that
              was modified.
            - power_up_state (float): Specifies the power up state set
              for the physical channel specified with the
              **physical_channel** input.
            - channel_type (:class:`nidaqmx.constants.AOPowerUpOutputBehavior`):
              Specifies the output type for the physical channel
              specified with the **physical_channel** input.
        """
        size = len(physical_channels)
        states = numpy.zeros(size, dtype=numpy.float64)
        channel_types = numpy.zeros(size, dtype=numpy.int32)

        cfunc = lib_importer.cdll.DAQmxGetAnalogPowerUpStatesWithOutputType
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C','W')),
                        wrapped_ndpointer(dtype=numpy.int32,
                                          flags=('C','W'))]

        error_code = cfunc(
            flatten_channel_string(physical_channels), states, channel_types,
            size)

        check_for_error(error_code)

        power_up_states = []
        for p, s, c in zip(physical_channels, states, channel_types):
            power_up_states.append(
                AOPowerUpState(
                    physical_channel=p,
                    power_up_state=float(s),
                    channel_type=AOPowerUpOutputBehavior(c.value)))

        return power_up_states
Exemplo n.º 9
0
def _read_binary_u_16(task_handle,
                      read_array,
                      num_samps_per_chan,
                      timeout,
                      fill_mode=FillMode.GROUP_BY_CHANNEL):
    samps_per_chan_read = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxReadBinaryU16
    if cfunc.argtypes is None:
        with cfunc.arglock:
            if cfunc.argtypes is None:
                cfunc.argtypes = [
                    lib_importer.task_handle, ctypes.c_int, ctypes.c_double,
                    ctypes.c_int,
                    wrapped_ndpointer(dtype=numpy.uint16,
                                      flags=('C', 'W')), ctypes.c_uint,
                    ctypes.POINTER(ctypes.c_int),
                    ctypes.POINTER(c_bool32)
                ]

    error_code = cfunc(task_handle, num_samps_per_chan,
                       timeout, fill_mode.value, read_array,
                       numpy.prod(read_array.shape),
                       ctypes.byref(samps_per_chan_read), None)
    check_for_error(error_code)

    return samps_per_chan_read.value
Exemplo n.º 10
0
    def poly_reverse_coeff(self):
        """
        List[float]: Specifies a list of coefficients for the polynomial
            that converts scaled values to pre-scaled values. Each
            element of the list corresponds to a term of the equation.
            For example, if index three of the list is 9, the fourth
            term of the equation is 9y^3.
        """
        cfunc = lib_importer.windll.DAQmxGetScalePolyReverseCoeff
        cfunc.argtypes = [
            ctypes_byte_str,
            wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
            ctypes.c_uint
        ]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.float64)

            size_or_code = cfunc(self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return val.tolist()
Exemplo n.º 11
0
    def table_scaled_vals(self):
        """
        List[float]: Specifies a list of scaled values. These values map
            directly to the values in **table_pre_scaled_vals**.
        """
        cfunc = lib_importer.windll.DAQmxGetScaleTableScaledVals
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C', 'W')), ctypes.c_uint
                    ]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.float64)

            size_or_code = cfunc(self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return val.tolist()
    def ai_meas_types(self):
        """
        List[:class:`nidaqmx.constants.UsageTypeAI`]: Indicates the
            measurement types supported by the channel.
        """
        cfunc = lib_importer.windll.DAQmxGetPhysicalChanAISupportedMeasTypes
        cfunc.argtypes = [
            ctypes_byte_str, wrapped_ndpointer(dtype=numpy.int32,
            flags=('C','W')), ctypes.c_uint]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.int32)

            size_or_code = cfunc(
                self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return [UsageTypeAI(e) for e in val]
    def teds_template_ids(self):
        """
        List[int]: Indicates the IDs of the templates in the bitstream
            in **teds_bit_stream**.
        """
        cfunc = lib_importer.windll.DAQmxGetPhysicalChanTEDSTemplateIDs
        cfunc.argtypes = [
            ctypes_byte_str, wrapped_ndpointer(dtype=numpy.uint32,
            flags=('C','W')), ctypes.c_uint]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.uint32)

            size_or_code = cfunc(
                self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return val.tolist()
    def write_to_teds_from_array(
            self, bit_stream=None,
            basic_teds_options=WriteBasicTEDSOptions.DO_NOT_WRITE):
        """
        Writes data from a 1D list of 8-bit unsigned integers to the
        TEDS sensor.

        Args:
            bit_stream (Optional[List[int]]): Is the TEDS bitstream to
                write to the sensor. This bitstream must be constructed
                according to the IEEE 1451.4 specification.
            basic_teds_options (Optional[nidaqmx.constants.WriteBasicTEDSOptions]): 
                Specifies how to handle basic TEDS data in the
                bitstream.
        """
        if bit_stream is None:
            bit_stream = []

        bit_stream = numpy.uint8(bit_stream)

        cfunc = lib_importer.windll.DAQmxWriteToTEDSFromArray
        cfunc.argtypes = [
            ctypes_byte_str, wrapped_ndpointer(dtype=numpy.uint8,
            flags=('C','W')), ctypes.c_uint, ctypes.c_int]

        error_code = cfunc(
            self._name, bit_stream, len(bit_stream), basic_teds_options.value)
        check_for_error(error_code)
    def ao_power_amp_scaling_coeff(self):
        """
        List[float]: Indicates the coefficients of a polynomial equation
            used to scale from pre-amplified values.
        """
        cfunc = lib_importer.windll.DAQmxGetAOPowerAmpScalingCoeff
        cfunc.argtypes = [
            ctypes_byte_str, wrapped_ndpointer(dtype=numpy.float64,
            flags=('C','W')), ctypes.c_uint]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.float64)

            size_or_code = cfunc(
                self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return val.tolist()
Exemplo n.º 16
0
def _write_binary_u_16(task_handle,
                       write_array,
                       num_samps_per_chan,
                       auto_start,
                       timeout,
                       data_layout=FillMode.GROUP_BY_CHANNEL):
    samps_per_chan_written = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxWriteBinaryU16
    if cfunc.argtypes is None:
        with cfunc.arglock:
            if cfunc.argtypes is None:
                cfunc.argtypes = [
                    lib_importer.task_handle, ctypes.c_int, c_bool32,
                    ctypes.c_double, ctypes.c_int,
                    wrapped_ndpointer(dtype=numpy.uint16, flags=('C', 'W')),
                    ctypes.POINTER(ctypes.c_int),
                    ctypes.POINTER(c_bool32)
                ]

    error_code = cfunc(task_handle, num_samps_per_chan, auto_start, timeout,
                       data_layout.value, write_array,
                       ctypes.byref(samps_per_chan_written), None)
    check_for_error(error_code)

    return samps_per_chan_written.value
Exemplo n.º 17
0
    def ao_power_up_output_types(self):
        """
        List[:class:`nidaqmx.constants.AOPowerUpOutputBehavior`]:
            Indicates the power up output types supported by the
            channel.
        """
        cfunc = (lib_importer.windll.
                 DAQmxGetPhysicalChanAOSupportedPowerUpOutputTypes)
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str, wrapped_ndpointer(dtype=numpy.int32,
                        flags=('C','W')), ctypes.c_uint]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.int32)

            size_or_code = cfunc(
                self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return [AOPowerUpOutputBehavior(e) for e in val]
Exemplo n.º 18
0
    def teds_bit_stream(self):
        """
        List[int]: Indicates the TEDS binary bitstream without
            checksums.
        """
        cfunc = lib_importer.windll.DAQmxGetPhysicalChanTEDSBitStream
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str, wrapped_ndpointer(dtype=numpy.uint8,
                        flags=('C','W')), ctypes.c_uint]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.uint8)

            size_or_code = cfunc(
                self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return val.tolist()
Exemplo n.º 19
0
    def ai_sensor_power_voltage_range_vals(self):
        """
        List[float]: Indicates pairs of sensor power voltage ranges
            supported by this channel. Each pair consists of the low
            value followed by the high value.
        """
        cfunc = (lib_importer.windll.
                 DAQmxGetPhysicalChanAISensorPowerVoltageRangeVals)
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C', 'W')), ctypes.c_uint
                    ]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.float64)

            size_or_code = cfunc(self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return val.tolist()
Exemplo n.º 20
0
def _read_digital_lines(task_handle,
                        read_array,
                        num_samps_per_chan,
                        timeout,
                        fill_mode=FillMode.GROUP_BY_CHANNEL):
    samps_per_chan_read = ctypes.c_int()
    num_bytes_per_samp = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxReadDigitalLines
    cfunc.argtypes = [
        lib_importer.task_handle, ctypes.c_int, ctypes.c_double, ctypes.c_int,
        wrapped_ndpointer(dtype=numpy.bool, flags=('C', 'W')), ctypes.c_uint,
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(c_bool32)
    ]

    error_code = cfunc(task_handle, num_samps_per_chan,
                       timeout, fill_mode.value, read_array,
                       numpy.prod(read_array.shape),
                       ctypes.byref(samps_per_chan_read),
                       ctypes.byref(num_bytes_per_samp), None)
    check_for_error(error_code)

    ReadDigitalLinesReturnData = (collections.namedtuple(
        'ReadDigitalLinesReturnData',
        ['samps_per_chan_read', 'num_bytes_per_samp']))

    return ReadDigitalLinesReturnData(samps_per_chan_read.value,
                                      num_bytes_per_samp.value)
    def do_samp_modes(self):
        """
        List[:class:`nidaqmx.constants.AcquisitionType`]: Indicates the
            sample modes supported by devices that support sample
            clocked digital output.
        """
        cfunc = lib_importer.windll.DAQmxGetPhysicalChanDOSampModes
        cfunc.argtypes = [
            ctypes_byte_str, wrapped_ndpointer(dtype=numpy.int32,
            flags=('C','W')), ctypes.c_uint]

        temp_size = 0
        while True:
            val = numpy.zeros(temp_size, dtype=numpy.int32)

            size_or_code = cfunc(
                self._name, val, temp_size)

            if is_array_buffer_too_small(size_or_code):
                # Buffer size must have changed between calls; check again.
                temp_size = 0
            elif size_or_code > 0 and temp_size == 0:
                # Buffer size obtained, use to retrieve data.
                temp_size = size_or_code
            else:
                break

        check_for_error(size_or_code)

        return [AcquisitionType(e) for e in val]
Exemplo n.º 22
0
    def poly_reverse_coeff(self, val):
        val = numpy.float64(val)
        cfunc = lib_importer.windll.DAQmxSetScalePolyReverseCoeff
        cfunc.argtypes = [
            ctypes_byte_str,
            wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
            ctypes.c_uint
        ]

        error_code = cfunc(self._name, val, len(val))
        check_for_error(error_code)
Exemplo n.º 23
0
    def table_scaled_vals(self, val):
        val = numpy.float64(val)
        cfunc = lib_importer.windll.DAQmxSetScaleTableScaledVals
        cfunc.argtypes = [
            ctypes_byte_str,
            wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
            ctypes.c_uint
        ]

        error_code = cfunc(self._name, val, len(val))
        check_for_error(error_code)
Exemplo n.º 24
0
    def set_analog_power_up_states_with_output_type(
            self, power_up_states):
        """
        Updates power up states for analog physical channels.

        Args:
            power_up_states (List[nidaqmx.types.AOPowerUpState]):
                Contains the physical channels and power up states to
                set. Each element of the list contains a physical channel
                and the power up state to set for that physical channel.

                - physical_channel (str): Specifies the physical channel to
                  modify.
                - power_up_state (float): Specifies the power up state
                  to set for the physical channel specified with the
                  **physical_channel** input.
                - channel_type (:class:`nidaqmx.constants.AOPowerUpOutputBehavior`):
                  Specifies the output type for the physical channel
                  specified with the **physical_channel** input.
        """
        physical_channel = flatten_channel_string(
            [p.physical_channel for p in power_up_states])
        state = numpy.float64(
            [p.power_up_state for p in power_up_states])
        channel_type = numpy.int32(
            [p.channel_type.value for p in power_up_states])

        cfunc = lib_importer.cdll.DAQmxSetAnalogPowerUpStatesWithOutputType
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C','W')),
                        wrapped_ndpointer(dtype=numpy.int32,
                                          flags=('C','W'))]

        error_code = cfunc(
            physical_channel, state, channel_type, len(power_up_states))
        check_for_error(error_code)
Exemplo n.º 25
0
    def poly_forward_coeff(self, val):
        val = numpy.float64(val)
        cfunc = lib_importer.windll.DAQmxSetScalePolyForwardCoeff
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.float64,
                                          flags=('C', 'W')), ctypes.c_uint
                    ]

        error_code = cfunc(self._name, val, len(val))
        check_for_error(error_code)
Exemplo n.º 26
0
def _read_counter_u_32(task_handle, read_array, num_samps_per_chan, timeout):
    samps_per_chan_read = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxReadCounterU32
    cfunc.argtypes = [
        lib_importer.task_handle, ctypes.c_int, ctypes.c_double,
        wrapped_ndpointer(dtype=numpy.uint32, flags=('C', 'W')), ctypes.c_uint,
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(c_bool32)
    ]

    error_code = cfunc(task_handle, num_samps_per_chan, timeout, read_array,
                       numpy.prod(read_array.shape),
                       ctypes.byref(samps_per_chan_read), None)
    check_for_error(error_code)

    return samps_per_chan_read.value
Exemplo n.º 27
0
def _write_raw(task_handle, num_samps_per_chan, numpy_array, auto_start,
               timeout):
    samps_per_chan_written = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxWriteRaw
    cfunc.argtypes = [
        lib_importer.task_handle, ctypes.c_int, c_bool32, ctypes.c_double,
        wrapped_ndpointer(dtype=numpy_array.dtype, flags=('C', 'W')),
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(c_bool32)
    ]

    error_code = cfunc(task_handle, num_samps_per_chan, auto_start, timeout,
                       numpy_array, ctypes.byref(samps_per_chan_written), None)
    check_for_error(error_code)

    return samps_per_chan_written.value
Exemplo n.º 28
0
    def cfg_watchdog_do_expir_states(self, expiration_states):
        """
        Configures the expiration states for a digital watchdog timer task.

        Args:
            expiration_states
                (List[nidaqmx.system.watchdog.DOExpirationState]):
                Contains the states to which to set digital physical channels
                when the watchdog timer expires. Each element of the list
                contains a digital physical channel name and the corresponding
                state for that digital physical channel.

                physical_channel (str): Specifies the digital output channel to
                    modify. You cannot modify dedicated digital input lines.
                expiration_state (nidaqmx.constants.Level): Specifies the
                    value to set the channel to upon expiration.
        Returns:
            List[nidaqmx.system._watchdog_modules.expiration_state.ExpirationState]:

            Indicates the list of objects representing the configured
            expiration states.
        """
        channel_names = flatten_channel_string(
            [e.physical_channel for e in expiration_states])
        expir_state = numpy.int32(
            [e.expiration_state.value for e in expiration_states])

        cfunc = lib_importer.windll.DAQmxCfgWatchdogDOExpirStates
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        lib_importer.task_handle, ctypes_byte_str,
                        wrapped_ndpointer(dtype=numpy.int32, flags=('C', 'W')),
                        ctypes.c_uint
                    ]

        error_code = cfunc(self._handle, channel_names, expir_state,
                           len(expiration_states))
        check_for_error(error_code)

        return [
            ExpirationState(self._handle, e.physical_channel)
            for e in expiration_states
        ]
Exemplo n.º 29
0
def _read_raw(task_handle, read_array, num_samps_per_chan, timeout):
    samples_read = ctypes.c_int()
    number_of_bytes_per_sample = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxReadRaw
    cfunc.argtypes = [
        lib_importer.task_handle, ctypes.c_int, ctypes.c_double,
        wrapped_ndpointer(dtype=read_array.dtype, flags=('C', 'W')),
        ctypes.c_uint,
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(c_bool32)
    ]

    error_code = cfunc(task_handle, num_samps_per_chan, timeout, read_array,
                       read_array.nbytes, ctypes.byref(samples_read),
                       ctypes.byref(number_of_bytes_per_sample), None)
    check_for_error(error_code)

    return samples_read.value, number_of_bytes_per_sample.value
Exemplo n.º 30
0
def _read_counter_f_64_ex(task_handle,
                          read_array,
                          num_samps_per_chan,
                          timeout,
                          fill_mode=FillMode.GROUP_BY_CHANNEL):
    samps_per_chan_read = ctypes.c_int()

    cfunc = lib_importer.windll.DAQmxReadCounterF64Ex
    cfunc.argtypes = [
        lib_importer.task_handle, ctypes.c_int, ctypes.c_double, ctypes.c_int,
        wrapped_ndpointer(dtype=numpy.float64, flags=('C', 'W')),
        ctypes.c_uint,
        ctypes.POINTER(ctypes.c_int),
        ctypes.POINTER(c_bool32)
    ]

    error_code = cfunc(task_handle, num_samps_per_chan,
                       timeout, fill_mode.value, read_array,
                       numpy.prod(read_array.shape),
                       ctypes.byref(samps_per_chan_read), None)
    check_for_error(error_code)

    return samps_per_chan_read.value