hil_task_is_valid hil_task_flush navigation bar

Table of Contents

hil_task_start

Starts a task running at the indicated sampling rate.

Description

The hil_task_start function starts a task running. The task runs at the sampling frequency specified and processes the number of samples specified. If the number of samples is set to INFINITE then the task runs until hil_task_stop is called.

Prototype

t_error 
hil_task_start(t_task task, t_clock clock, t_double frequency, t_uint32 num_samples);
    

Parameters

t_task task

A handle to the task, as returned by one of the task creation functions.

t_clock clock

The clock used to time the operation. Note that some clocks allow faster sampling rates than others. See Clocks for more information on clocks.

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

t_double frequency

The frequency in Hertz at which to process samples. For example, if frequency is set to 1000, then the hil_task_start function causes the task to process one sample every millisecond.

t_uint32 num_samples

The total number of samples to process. Each "sample" consists of all the channels specified when the task was created. For example, if frequency is set to 1000 and num_samples is set to 5000, then the task will run for 5 seconds, processing 5000 samples. If the number of samples is set to INFINITE then the task will run until hil_task_stop is called.

Return value

The return value is 0 if the task is started successfully. Otherwise a negative error code is returned. Error codes are defined in quanser_errors.h. A suitable error message may be retrieved using msg_get_error_message.

Error codes

QERR_HIL_TASK_START_NOT_SUPPORTED

This function is not supported by the board-specific HIL driver for this board type.

QERR_INVALID_TASK_HANDLE

An invalid task handle was passed as an argument. Once a task has been deleted using hil_task_delete the task handle is invalid.

QERR_INVALID_OPERATION_HANDLE

An invalid operation handle was passed as an argument to the board-specific HIL driver. Once a task has been deleted using hil_task_delete the operation handle is invalid.

QERR_ANALOG_RESOURCE_IN_USE

The analog-to-digital converter on the HIL board is currently in use by another operation.

QERR_OUT_OF_REQUIRED_SYSTEM_RESOURCES

There are not enough system resources to perform the requested operation. Try rebooting, requesting fewer samples, or adding more memory to your machine.

QERR_CLOCK_FREQUENCY_NOT_POSITIVE

The clock frequency specified is negative or zero. The clock frequency must be positive.

QERR_CLOCK_FREQUENCY_TOO_HIGH

The clock frequency is too high for the specified clock. Try using a different clock. Hardware clocks are generally faster than the system clocks.

QERR_CLOCK_FREQUENCY_TOO_LOW

The clock frequency is too low for the specified clock. Try using a different clock. System clocks are preferable for low frequencies so that hardware clocks remain available for higher frequency operations.

QERR_CLOCK_FREQUENCY_INVALID

The clock frequency is invalid for the specified clock, or the clock may be unavailable. Try using a different clock.

QERR_CLOCK_NOT_SUPPORTED

The specified clock is not supported by the board-specific HIL driver for this board.

QERR_DRIVER_INCOMPATIBLE_WITH_BOARD_DLL

The board-specific HIL driver passed an invalid parameter to the operating system specific kernel-level driver for the board. The board-specific HIL driver is likely not compatible with the operating system specific kernel-level driver for the board. Make sure both are up-to-date and compatible versions.

QERR_HARDWARE_CLOCK_IN_USE

The specified hardware clock is already in use for another operation and the board-specific HIL driver for this board does not permit sharing of the hardware clock or a PWM channel is based on a hardware clock that is already in use for another operation.

QERR_INTERRUPT_VECTOR_IN_USE

The interrupt vector required by the board is in use by another device and the board-specific HIL driver does not support sharing of the interrupt vector.

QERR_WRONG_CLOCK_MODE

A PWM channel is based on a hardware clock that is in the wrong mode for this operation. Use the hil_set_clock_mode function to change modes.

Requirements

Include Files

Libraries

hil.h

hil.lib;quanser_runtime.lib;quanser_common.lib

Examples


/*
* Reads 5000 samples at 1 kHz from the first four analog input channels, using SYSTEM_CLOCK_1.
* Return values are ignored for simplicity.
*/

t_uint32 channels[]        = { 0, 1, 2, 3 };
t_double frequency         = 1000;
t_uint32 samples           = 5000;
t_uint32 samples_in_buffer = frequency;
t_uint32 samples_to_read   = 1;

static t_double buffer[4];
t_task task;

hil_task_create_analog_reader(board, samples_in_buffer, channels, ARRAY_LENGTH(channels), &task);
hil_task_start(task, SYSTEM_CLOCK_1, frequency, samples);
for (int index = 0; index < samples; index += samples_to_read) {
    hil_task_read_analog(task, samples_to_read, buffer);
    ...
}
hil_task_stop(task);
hil_task_delete(task);
    

 

navigation bar