hil_task_read_write hil_task_flush navigation bar

Table of Contents

hil_task_start

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.

Starts a task.

Syntax

err = hil_task_start(task, clock, frequency, num_samples)
    

Description

Starts a task. The task will begin transferring data to or from the internal buffer at the given sampling rate, using the specified clock. The total number of samples transferred will equal num_samples unless the task is stopped prematurely using hil_task_stop or the internal buffer overflows. Setting num_samples to -1 indicates an infinite number of samples.

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.

clock

The clock to use as a timebase. Hardware clocks are numbered incrementally starting at 0, with 0 meaning HARDWARE_CLOCK_0, 1 meaning HARDWARE_CLOCK_1, etc. The number of clocks available depends on the board selected. Refer to Clocks for more information.

Select a board type from the list for board-specific details: .

frequency

The sampling frequency in Hertz at which samples will be collected.

num_samples

The total number of samples to collect or generate before stopping the task. Set to -1 to specify an infinite number samples i.e., hil_task_stop is required in this case to stop the task.

Outputs

err

A negative error code or zero on success.

Examples

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

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

for i=1:10
    % Reads 500 samples of analog channel 0.
    volts = hil_task_read_analog(task, 500);
    ...
end;

% 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