quanser.hardware.task.set_buffer_overflow_mode quanser.hardware.task.stop navigation bar

Table of Contents

quanser.hardware.task.start

Starts a task.

Syntax

err = task.start(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 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 instance returned by one of the quanser.hardware.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., 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 = board.task_create_analog_reader(1000, 0);

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

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

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

See Also

 

navigation bar