hil_task_start hil_task_stop navigation bar

Table of Contents

hil_task_flush

Flushes the task buffer.

Description

The hil_task_flush function flushes the task buffer for a writer or read-writer task. This function has no effect on reader tasks. Flushing the task buffer ensures that all the data written to the task buffer has been transferred to the actual hardware. This function does not return until all the data in the task buffer has been flushed to the hardware or the task is stopped.

Prototype

t_error
hil_task_flush(t_task task);
    

Parameters

t_task task

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

Return value

The return value is 0 if the task is flushed 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_FLUSH_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_BUFFER_OVERFLOW

This error occurs if the task buffer ran out of data between the last write operation and the call to hil_task_flush. The sampling frequency is too fast for the rate at which data is being written to the buffer.

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_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.

Requirements

Include Files

Libraries

hil.h

hil.lib;quanser_runtime.lib;quanser_common.lib

Examples


/*
* Writes 5000 samples at 1 kHz to the first four analog output 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_write  = 100;

static t_double buffer[100][4];
t_task task;

/* Fill buffer */
...
hil_task_create_analog_writer(board, samples_in_buffer, channels, ARRAY_LENGTH(channels), &task);
hil_task_write_analog(task, samples_to_write, buffer); /* pre-fill the task buffer prior to starting the task */
hil_task_start(task, SYSTEM_CLOCK_1, frequency, samples);
for (int index = samples_to_write; index < samples; index += samples_to_write) {
    /* Fill buffer */
    ...
    hil_task_write_analog(task, samples_to_write, buffer); /* does not wait for data to be written to the hardware, */
    ...                                                    /* only waits for space in the task buffer */
}
hil_task_flush(task); /* make sure all data has been written to the hardware */
hil_task_stop(task);
hil_task_delete(task);
    

 

navigation bar