hil_task_start hil_task_stop navigation bar

Table of Contents

hil_task_flush

Deprecated

The HIL API MATLAB functions have been deprecated in favour of the new quanser.hardware.hil class, which has support for code generation for Quanser targets. Hence, with the new hil class it is possible to run MATLAB scripts in real-time on Quanser targets, while making use of the Quanser hardware.

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

Syntax

[samples_flushed, err] = hil_task_flush(task)
    

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 handle returned by one of the 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  = hil_task_create_analog_writer(board, 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.
hil_task_write_analog(task, 500, volts);

% Start the task using SYSTEM_CLOCK_1 at 1 kHz. Generate up to 5000 samples.
hil_task_start(task, -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.
    hil_task_write_analog(task, 500, volts);
    ...
end;

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

% Always good to call hil_task_stop even if the task stops itself.
hil_task_stop(task);
hil_task_delete(task);
    

See Also

 

navigation bar