quanser.hardware.task.read_digital_write_digital quanser.hardware.task.read_write navigation bar

Table of Contents

quanser.hardware.task.read_other_write_other

Reads the specified number of other samples and writes the specified number of other samples to the task's internal buffer.

Syntax

[input_values, samples_read, err] = task.read_other_write_other(num_samples, output_values)
    

Description

Reads the specified number of other samples and writes the specified number of other samples to the task's internal buffer. This function will block until the requested number of samples have been read or can be written or the task is stopped. Note that the written samples are only transferred to the internal buffer. The samples may not appear at the outputs until later. Use task.flush to wait for all samples to be written to the outputs.

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

num_samples

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

output_values

A matrix of other values to write. There must be one row for each channel and one column for each sample.

Outputs

input_values

A matrix of other values read, as doubles. There is one row for each channel and one column for each sample.

n

The number of samples written. 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 other channel 5, and write to other channels 0 and 3, with an internal buffer of 1000 samples.
task = board.task_create_other_reader_other_writer(1000, [0 3], 5);

% Random values between 0 and 1.
values = rand(1,500);

% Writes 500 samples to other channel 5. Won't block.
task.write_other(values);

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

for i=1:10
    % Random values between 0 and 1.
    values = rand(1,500);

    % Reads 500 samples from other channels 0 and 3 and writes 500 samples to other channel 5.
    [v, n] = task.read_other_write_other(500, duty);
    ...
end;

% Make sure any samples remaining in the internal buffer have been written to the outputs.
task.flush;
task.stop;
task.close;
    

See Also

 

navigation bar