hil_read_analog_codes End of trail navigation bar

Table of Contents

hil_read_write

Reads from inputs and writes to outputs immediately.

Description

The hil_read_write function reads from the specified analog, encoder, digital and/or other input channels and writes to the specified analog, PWM, digital and/or other output channels in a single function call. The write operation occurs immediately following the read operation. Since the read-write operation occurs at the lowest level the read and write occur virtually concurrently. The function does not return until the data has been read and written.

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_read_write function failing to read or write the digital I/O as expected.

The interpretation of the PWM data to be written depends upon the PWM mode. Typically the data is interpreted as a duty cycle, in which a magnitude of 0.0 denotes a 0% duty cycle and magnitude of 1.0 indicates a 100% duty cycle. The sign determines the polarity of the output for those boards supporting bidirectional PWM outputs. However, other PWM modes are possible with some boards. Refer to the hil_set_pwm_mode function for details.

Prototype

t_error 
hil_read_analog_write_analog(t_card card
                             const t_uint32  analog_input_channels[],   t_uint32 num_analog_input_channels,
                             const t_uint32  encoder_input_channels[],  t_uint32 num_encoder_input_channels,
                             const t_uint32  digital_input_channels[],  t_uint32 num_digital_input_channels,
                             const t_uint32  other_input_channels[],    t_uint32 num_other_input_channels,
                             const t_uint32  analog_output_channels[],  t_uint32 num_analog_output_channels,
                             const t_uint32  pwm_output_channels[],     t_uint32 num_pwm_output_channels,
                             const t_uint32  digital_output_channels[], t_uint32 num_digital_output_channels,
                             const t_uint32  other_output_channels[],   t_uint32 num_other_output_channels,
                             t_double        analog_input_buffer[],
                             t_int32         encoder_input_buffer[],
                             t_boolean       digital_input_buffer[],
                             t_double        other_input_buffer[],
                             const t_double  analog_output_buffer[],
                             const t_double  pwm_output_buffer[],
                             const t_boolean digital_output_buffer[],
                             const t_double  other_output_buffer[]);
    

Parameters

t_card card

A handle to the board, as returned by hil_open

const t_uint32 [] analog_input_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 input channels are required then this parameter may be NULL. In this case, num_analog_input_channels must be zero.

t_uint32 num_analog_input_channels

t_uint32

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

const t_uint32 [] encoder_input_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 input channels are required then this parameter may be NULL. In this case, num_encoder_input_channels must be zero.

t_uint32 num_encoder_input_channels

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

const t_uint32 [] digital_input_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 input channels are required then this parameter may be NULL. In this case, num_digital_input_channels must be zero.

t_uint32 num_digital_input_channels

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

const t_uint32 [] other_input_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 input channels are required then this parameter may be NULL. In this case, num_other_input_channels must be zero.

t_uint32 num_other_input_channels

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

cont t_uint32 [] analog_output_channels

An array containing the channel numbers of the analog outputs to be written.

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

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

t_uint32 num_analog_output_channels

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

cont t_uint32 [] pwm_output_channels

An array containing the channel numbers of the PWM outputs to be written.

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

If no PWM output channels are required then this parameter may be NULL. In this case, num_pwm_output_channels must be zero.

t_uint32 num_pwm_output_channels

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

const t_uint32 digital_output_channels

An array containing the channel numbers of the digital outputs to be written.

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

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

t_uint32 num_digital_output_channels

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

cosnt t_uint32 [] other_output_channels

An array containing the channel numbers of the other outputs to be written.

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

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

t_uint32 num_other_output_channels

t_uint32

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

t_double [] analog_input_buffer

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

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

t_int32 [] encoder_input_buffer

An array for receiving the counter values read from the encoder inputs. The array must contain num_encoder_input_channels elements. Each element in the returned encoder_input_buffer array will correspond to the same element in the encoder_input_channels array.

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

t_boolean [] digital_input_buffer

An array for receiving the voltage values read from the digital inputs. The array must contain num_digital_input_channels elements. Each element in the returned digital_input_buffer array will correspond to the same element in the digital_input_channels array.

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

t_double [] other_input_buffer

An array for receiving the values read from the other inputs. The array must contain num_other_input_channels elements. Each element in the returned other_input_buffer array will correspond to the same element in the other_input_channels array.

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

const t_double [] analog_output_buffer

An array of voltage values to write to the analog outputs. The array must contain num_analog_output_channels elements. Each element in the analog_output_buffer array corresponds to the same element in the analog_output_channels array.

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

const t_double [] pwm_output_buffer

An array containing the values to write to the PWM outputs. How these values are interpreted depends on the PWM mode. The PWM mode is configured using the hil_set_pwm_mode function. The array must contain num_pwm_output_channels elements. Each element in the pwm_output_buffer array correspondsis to the same element in the pwm_output_channels array.

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

const t_boolean [] digital_output_buffer

An array of voltage values to write to the digital outputs. The array must contain num_digital_output_channels elements. Each element in the digital_output_buffer array corresponds to the same element in the digital_output_channels array.

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

const t_double [] other_output_buffer

An array of values to write to the other outputs. The array must contain num_other_output_channels elements. Each element in the other_output_buffer array corresponds to the same element in the other_output_channels array.

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

Return value

The return value is 0 if the I/O operation is performed 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_WRITE_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_TOO_MANY_ANALOG_OUTPUT_CHANNELS

Too many analog output channels were specified.

QERR_INVALID_ANALOG_OUTPUT_CHANNEL

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

Too many PWM output channels were specified.

QERR_INVALID_PWM_OUTPUT_CHANNEL

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

QERR_HARDWARE_CLOCK_IN_USE

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

QERR_WRONG_CLOCK_MODE

One of the PWM output channels 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.

QERR_TOO_MANY_DIGITAL_OUTPUT_CHANNELS

Too many digital output channels were specified.

QERR_INVALID_DIGITAL_OUTPUT_CHANNEL

One of the digital output 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_OUTPUT_CHANNELS

Too many other output channels were specified.

QERR_INVALID_OTHER_OUTPUT_CHANNEL

One of the other output 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 the first two analog input channels, the first two encoder input channels
* and the first two digital channels and writes to the first two analog output channels
* and digital channels 5-7.
*/

t_uint32  analog_input_channels[]  = { 0, 1 };
t_uint32  encoder_input_channels[] = { 0, 1 };
t_uint32  digital_input_channels[] = { 0, 1 };
t_double  analog_input_buffer[2];
t_int32   encoder_input_buffer[2];
t_boolean digital_input_buffer[2];

t_uint32  analog_output_channels[]  = { 0, 1 };
t_uint32  digital_output_channels[] = { 5, 6, 7 };
t_double  analog_output_buffer[]    = { 0.5, 1.5 };
t_boolean digital_output_buffer[]   = { 1, 0, 1 };

t_error result = hil_read_write(board
    , analog_input_channels,   ARRAY_LENGTH(analog_input_channels)
    , encoder_input_channels,  ARRAY_LENGTH(encoder_input_channels)
    , digital_input_channels,  ARRAY_LENGTH(digital_input_channels)
    , NULL,                    0
    , analog_output_channels,  ARRAY_LENGTH(analog_output_channels)
    , NULL,                    0
    , digital_output_channels, ARRAY_LENGTH(digital_output_channels)
    , NULL,                    0
    , analog_input_buffer
    , encoder_input_buffer
    , digital_input_buffer
    , NULL
    , analog_output_buffer
    , NULL
    , digital_output_buffer
    , NULL
);
    

 

navigation bar