hil_read_other hil_write_analog navigation bar

Table of Contents

hil_read

Reads from analog, encoder, digital and/or other inputs immediately.

Description

The hil_read function reads from the specified input channels immediately. The function does not return until the data has been read.

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 must be configured as inputs using this function. Failure to configure the digital I/O may result in the hil_read function failing to read those inputs.

Prototype

t_error hil_read(t_card card, 
                 const t_uint32 analog_channels[],  t_uint32 num_analog_channels,
                 const t_uint32 encoder_channels[], t_uint32 num_encoder_channels,
                 const t_uint32 digital_channels[], t_uint32 num_digital_channels,
                 const t_uint32 other_channels[],   t_uint32 num_other_channels,
                 t_double  analog_buffer[], 
                 t_int32   encoder_buffer[], 
                 t_boolean digital_buffer[], 
                 t_double  other_buffer[]);
    

Parameters

t_card card

A handle to the board, as returned by hil_open

const t_uint32 [] analog_channels

An array containing the channel numbers of the analog inputs to be read.

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

If no analog channels are required then this parameter may be NULL. In this case, num_analog_channels must be zero.

t_uint32 num_analog_channels

The number of channels specified in the analog_channels array. This parameter may be zero.

const t_uint32 [] encoder_channels

An array containing the channel numbers of the encoder inputs to be read.

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

If no encoder channels are required then this parameter may be NULL. In this case, num_encoder_channels must be zero.

t_uint32 num_encoder_channels

The number of channels specified in the encoder_channels array. This parameter may be zero.

const t_uint32 [] digital_channels

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

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

If no digital channels are required then this parameter may be NULL. In this case, num_digital_channels must be zero.

t_uint32 num_digital_channels

The number of channels specified in the digital_channels array. This parameter may be zero.

const t_uint32 [] other_channels

An array containing the channel numbers of the other inputs to be read.

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

If no other channels are required then this parameter may be NULL. In this case, num_other_channels must be zero.

t_uint32 num_other_channels

The number of channels specified in the other_channels array. This parameter may be zero.

t_double [] analog_buffer

An array for receiving the voltage values read from the analog inputs. The array must contain num_analog_channels elements. Each element in the returned analog_buffer array will correspond to the same element in the analog_channels array.

If no analog channels were specified then this parameter may be NULL.

t_int32 [] encoder_buffer

An array for receiving the count values read from the encoder inputs. The array must contain num_encoder_channels elements. Each element in the returned encoder_buffer array will correspond to the same element in the encoder_channels array.

If no encoder channels were specified then this parameter may be NULL.

t_boolean [] digital_buffer

An array for receiving the binary values read from the digital inputs. The array must contain num_digital_channels elements. Each element in the returned digital_buffer array will correspond to the same element in the digital_channels array.

If no digital channels were specified then this parameter may be NULL.

t_double [] other_buffer

An array for receiving the values read from the other inputs. The array must contain num_other_channels elements. Each element in the returned other_buffer array will correspond to the same element in the other_channels array.

If no other channels were specified then this parameter may be NULL.

Return value

The return value is 0 if the analog inputs are read 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_READ_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_TOO_MANY_ANALOG_INPUT_CHANNELS

Too many analog input channels were specified.

QERR_INVALID_ANALOG_INPUT_CHANNEL

One of the analog 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_ANALOG_RESOURCE_IN_USE

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

QERR_TOO_MANY_ENCODER_INPUT_CHANNELS

Too many encoder input channels were specified.

QERR_INVALID_ENCODER_INPUT_CHANNEL

One of the encoder 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_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_TOO_MANY_OTHER_INPUT_CHANNELS

Too many other input channels were specified.

QERR_INVALID_OTHER_INPUT_CHANNEL

One of the other 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_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.

Requirements

Include Files

Libraries

hil.h

hil.lib;quanser_runtime.lib;quanser_common.lib

Examples


/*
* Read two analog input channels, two encoder input channels and four digital input channels.
*/

t_uint32 analog_channels[]  = { 0, 1 };
t_uint32 encoder_channels[] = { 0, 1 };
t_uint32 digital_channels[] = { 0, 1, 2, 3 };

t_double  analog_buffer[2];
t_int32   encoder_buffer[2];
t_boolean digital_buffer[4];

t_error result = hil_read(board
                        , analog_channels,  ARRAY_LENGTH(analog_channels)
                        , encoder_channels, ARRAY_LENGTH(encoder_channels)
                        , digital_channels, ARRAY_LENGTH(digital_channels)
                        , NULL,             0   /* no other channels */
                        , analog_buffer
                        , encoder_buffer
                        , digital_buffer
                        , NULL
                        );
    

 

navigation bar