hil_task_create_encoder_reader hil_task_create_other_reader navigation bar

Table of Contents

hil_task_create_digital_reader

Creates a task for reading from digital inputs.

Description

The hil_task_create_digital_reader function creates a task for reading from the specified digital input channels. The task allows other operations to be performed while the digital inputs are being read "in the background". The data is read into an internal circular "task buffer" from which it can be read at any time using the hil_task_read_digital function. The size of this task buffer is determined by the samples_in_buffer parameter.

The task does not actually start reading from the digital inputs until the hil_task_start function is called. Before starting the task, the directions of the digital I/O lines should be set using the hil_set_digital_directions function. The task must be deleted when it is no longer in use using the hil_task_delete function, in order to free the system and hardware resources used by the task. See Tasks for more information on task.

Warning Many cards allow the digital I/O lines to be programmed as inputs or outputs. The digital I/O lines are configured as inputs or outputs using the hil_set_digital_directions function. All the channels which will be used as digital inputs or outputs must be configured accordingly using this function. Failure to configure the digital I/O may result in the hil_task_read_digital function failing to read or write the digital I/O as expected.

Prototype

t_error 
hil_task_create_digital_reader(t_card card, t_uint32 samples_in_buffer,
                               const t_uint32 digital_channels[], t_uint32 num_digital_channels,
                               t_task *task);
    

Parameters

t_card card

A handle to the board, as returned by hil_open.

t_uint32 samples_in_buffer

The number of samples in the task buffer. The hil_task_read_digital function cannot read more samples than this in a single call. If the task buffer overflows because hil_task_read_digital has not been called in time to remove the data from the task buffer then the next call to hil_task_read_digital will return an HIL_BUFFER_OVERFLOW error. See Tasks for more information on task buffers.

const t_uint32 [] digital_channels

An array containing the channel numbers of the digital inputs to be read by the task.

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

t_uint32 num_digital_channels

The number of channels specified in the digital_channels array.

t_task * task

A handle to the task is returned in the t_task variable passed in this parameter. This argument cannot be NULL. Pass the address of a variable of type t_task.

Return value

The return value is 0 if the task is created 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_CREATE_DIGITAL_READER_NOT_SUPPORTED

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

QERR_INVALID_CARD_HANDLE

An invalid card handle was passed as an argument. Once a card has been closed using hil_close the card handle is invalid.

QERR_TASK_ARGUMENT_IS_NULL

The task argument is NULL. A pointer to a t_task variable must be supplied because this variable must be passed to the other HIL task functions to refer to the task.

QERR_MISSING_DIGITAL_INPUTS

The digital input channels argument is NULL when the number of digital inputs specified is non-zero.

QERR_TOO_MANY_DIGITAL_INPUT_CHANNELS

Too many digital input channels were specified.

QERR_INVALID_DIGITAL_INPUT_CHANNEL

One of the digital input channels that was specified is not a valid channel number. Channel numbers range from 0 to one less than the number of channels.

QERR_DIGITAL_INPUT_CHANNELS_NOT_SUPPORTED

Digital input channels are not supported by this board.

QERR_INVALID_BOARD_HANDLE

An invalid board handle was passed as an argument to the board-specific HIL driver. Once a card has been closed using hil_close the board handle is invalid.

QERR_INVALID_BUFFER_HANDLE

An invalid buffer handle was passed to a board-specific HIL driver function.

QERR_OPERATION_ARGUMENT_IS_NULL

The operation argument to a board-specific HIL driver is NULL. This situation should never occur unless the user is calling the board-specific driver directly or memory has been corrupted.

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_INTERNAL_BUFFER_TOO_SMALL

The board-specific HIL driver used an internal buffer that was too small for 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_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_OUT_OF_MEMORY

There is not enough memory to perform the operation.

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 digital 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_boolean buffer[4];
t_task task;

hil_task_create_digital_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_digital(task, samples_to_read, buffer);
    ...
}
hil_task_stop(task);
hil_task_delete(task);
    

 

navigation bar