quanser.hardware.task.start quanser.hardware.task.stop navigation bar

Table of Contents

quanser.hardware.task.flush

Flushes any remaining samples from the task's internal buffer to the outputs.

Syntax

[samples_flushed, err] = task.flush
    

Description

Flushes any remaining samples from the task's internal buffer to the outputs. This function does not return until all the samples have been 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 one of the quanser.hardware.hil.task_create functions.

Outputs

samples_flushed

The number of samples flushed from the internal buffer.

err

A negative error code or zero on success.

Examples

% Creates a task to write to analog channel 0, with an internal buffer of 1000 samples.
task = board.task_create_analog_writer(1000, 0);

% Uniformly distributed random values between -5V and +5V.
volts = 5*(rand(1,500)-0.2)*2;

% Writes 500 samples to analog channel 0.
task.write_analog(500, volts);

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

for i=1:10
    % Uniformly distributed random values between -5V and +5V.
    volts = 5*(rand(1,500)-0.2)*2;

    % Writes 500 samples to analog channel 0.
    task.write_analog(500, volts);
    ...
end;

% Make sure all remaining samples in the internal buffer have been sent to the output.
task.flush;

% Always good to call task.stop even if the task stops itself.
task.stop;
task.close;
    

See Also

 

navigation bar