quanser.hardware.task.read_other quanser.hardware.task.write_analog navigation bar

Table of Contents

quanser.hardware.task.read

Reads the specified number of samples from the task's internal buffer.

Syntax

[analog_values, encoder_counts, digital_values, other_values, samples_read, err] = task.read(samples)
    

Description

Reads the specified number of samples from the task's internal buffer. This function will block until the requested number of samples has been read or the task is stopped.

Warning Many cards allow the digital I/O lines to be programmed as inputs or outputs. The digital I/O lines are configured as inputs or outputs using the quanser.hardware.hil.set_digital_directions function. All the channels which will be used as digital inputs must be configured as inputs using this function. Failure to configure the digital I/O may result in the task.read function failing to read those inputs.

If no err output is provided then it throws an exception if an error occurs. In generated code it prints the error message. Use hil_get_error_message to get the message associated with an error code.

Parameters

task

Task instance returned by quanser.hardware.hil.task_create_reader or quanser.hardware.hil.task_create_reader_writer.

samples

The number of samples to read. This number must be less than or equal to the internal buffer size assigned to the task in the quanser.hardware.hil.task_create_reader or quanser.hardware.hil.task_create_reader_writer call.

Outputs

analog_values

A matrix of analog values, as doubles. There is one row for each channel and one column for each sample. If no analog channels were specified in the call to quanser.hardware.hil.task_create_reader then this parameter may be an empty matrix, [].

encoder_values

A matrix of encoder values, as int32s. There is one row for each channel and one column for each sample. If no encoder channels were specified in the call to quanser.hardware.hil.task_create_reader then this parameter may be an empty matrix, [].

digital_values

A matrix of digital values, as int8s. There is one row for each channel and one column for each sample. If no digital channels were specified in the call to quanser.hardware.hil.task_create_reader then this parameter may be an empty matrix, [].

other_values

A matrix of other values, as doubles. There is one row for each channel and one column for each sample. If no other channels were specified in the call to quanser.hardware.hil.task_create_reader then this parameter may be an empty matrix, [].

samples_read

The number of samples read. This number will be equal to the number of samples specified unless the total number of samples specified in task.start has expired or the task has been stopped.

err

A negative error code or zero on success.

Examples

% Creates a task to read analog channels 0 and 3 and digital channel 5, with an internal buffer of 1000 samples.
task = board.task_create_reader(1000, [0 3], [], 5, []);

% Start the task using SYSTEM_CLOCK_1 at 1 kHz. Collect up to 5000 samples.
task.start(-1, 1000, 5000);

% Reads 500 samples of analog channels 0 and 3, and digital channel 5. Takes 0.5 seconds to complete read.
for i=1:10
    [volt, cnt, bits, xtra, n] = task.read(500);
    ...
end;

task.stop;
task.close;
    

See Also

 

navigation bar