Start of trail End of trail navigation bar

Table of Contents

quanser.hardware.hil Class

The quanser.hardware.hil class provides methods to access data acquisition hardware in a variety of ways. However, in order to use a board, it must first be opened using the static quanser.hardware.hil.open method. The open function returns an instance of the hil class whose methods may then be used to access the data acquisition hardware. When the board is no longer needed it should be closed using the close method.

The methods of the hil class may be grouped into the following categories:

To build and run scripts involving hardware access in real-time on Quanser targets, refer to the Basic Procedures for Scripts.

Static Functions

The quanser.hardware.hil class has the following static functions:

quanser.hardware.hil.get_version

Gets the Quanser HIL API version.

quanser.hardware.hil.open

Opens a HIL board.

quanser.hardware.hil.close_all

Closes all open HIL devices.

quanser.hardware.hil.esc_output

Generates a PWM output value suitable for an ESC command.

The first function is used to check the version information for the hil class itself. The version will match the version of the HIL API to which the class belongs. Version information can be useful to determine what features, drivers or updates may be available.

The second method is used to open a data acquisition card. This method returns an instance of the class, whose methods may then be used to access the hardware. When the board is no longer in use it must be closed using the close method. A board is first opened using the static quanser.hardware.hil.open method of the class as follows:

board = quanser.hardware.hil.open('qpid_e', '0');

This opens the first instance of a QPIDe data acquisition card. Refer to the documentation for the quanser.hardware.hil.open method for more details with regards to the arguments.

Configuration Functions

Once the board is open, the configuration functions are used to configure features of the card, such as setting the analog input ranges, or the directions of digital I/O channels. For cards that have reconfigurable I/O, such as digital outputs that can be reconfigured as PWM outputs, the set_card_specific_options method may be used. Since it can reconfigure pins on the board, it should be called immediately after the board is opened.

The following methods of the board instance may be used to configure the hardware:

close

Closes the given HIL device.

get_double_property

Get the values of the given double properties of the board.

get_integer_property

Get the values of the given integer properties of the board.

get_string_property

Get the values of the given string properties of the board.

is_valid

Indicates whether the given board represents a valid open board.

set_analog_input_configuration

Sets the configuration of the specified analog input channels(e.g. single-ended versus differential).

set_analog_input_ranges

Sets the voltage ranges of the specified analog input channels.

set_analog_output_ranges

Sets the voltage ranges of the specified analog output channels.

set_card_specific_options

Sets options that are specific to this particular card.

set_clock_frequency

Sets the frequencies of the specified hardware clocks.

set_clock_mode

Sets the modes of the specified hardware clocks.

set_digital_directions

Sets the directions (input or output) of the specified digital channels.

set_double_property

Set the values of the given double properties of the board.

set_encoder_counts

Sets the count values of the specified encoder channels.

set_encoder_filter_frequency

Sets the filter frequencies of the specified encoder channels.

set_encoder_quadrature_mode

Sets the quadrature modes of the specified encoder channels.

set_integer_property

Set the values of the given integer properties of the board.

set_pwm_configuration

Sets the configuration, alignment and polarity of the specified PWM channels.

set_pwm_deadband

Sets the deadband employed for the specified PWM channels.

set_pwm_duty_cycle

Sets the duty cycles of the specified PWM channels.

set_pwm_frequency

Sets the frequencies of the specified PWM channels.

set_pwm_mode

Sets the mode of the specified PWM channels.

set_string_property

Set the values of the given string properties of the board.

Immediate I/O Functions

The immediate I/O functions perform an immediate read and/or write to the hardware. Only a single sample is read and/or written, although a sample may consist of multiple channels of different types. Since a single sample is read and/or written, the immediate I/O functions are more suited for control applications where single-point access is generally required.

The immediate I/O functions are as follows:

read

Reads the specified channels.

read_analog

Reads the specified analog channels.

read_analog_codes

Reads the specified analog channels immediately, returning raw integer analog codes instead of voltages.

read_analog_write_analog

Reads from the specified analog input channels and writes to the specified analog output channels.

read_digital

Reads the specified digital channels.

read_digital_write_digital

Reads from the specified digital input channels and writes to the specified digital output channels.

read_encoder

Reads the specified encoder channels.

read_encoder_write_pwm

Reads from the specified encoder input channels and writes to the specified PWM output channels.

read_other

Reads the specified other channels.

read_other_write_other

Reads from the specified other input channels and writes to the specified other output channels.

read_write

Reads from the specified input channels and writes to the specified output channels.

write

Writes to the specified channels.

write_analog

Writes to the specified analog channels.

write_analog_codes

Writes to the specified analog channels. The raw integer analog codes are used instead of voltages.

write_digital

Writes to the specified digital channels.

write_other

Writes to the specified other channels.

write_pwm

Writes to the specified PWM channels.

Buffered I/O Functions

The buffered I/O functions are used to read and/or write a buffer of samples at a fixed sampling rate. Multiple samples are read and/or written, where each sample may consist of multiple channels of different types. Buffered I/O reflects the more traditional use of a data acquisition card. Hence, the buffered I/O functions are mmore suitable for data acquisition applications rather than control because they process inputs in bulk as opposed to one sample at a time.

The buffered I/O functions are as follows:

read_analog_buffer

Reads the specified number of samples from the analog channels at the indicated sampling rate.

read_analog_write_analog_buffer

Reads from the specified analog input channels and writes to the analog output channels at the given sampling rate, for the indicated number of samples.

read_buffer

Reads the specified number of samples from a combination of channels at the indicated sampling rate.

read_digital_buffer

Reads the specified number of samples from the digital channels at the indicated sampling rate.

read_digital_write_digital_buffer

Reads from the specified digital input channels and writes to the digital output channels at the given sampling rate, for the indicated number of samples.

read_encoder_buffer

Reads the specified number of samples from the encoder channels at the indicated sampling rate.

read_encoder_write_pwm_buffer

Reads from the specified encoder input channels and writes to the PWM output channels at the given sampling rate, for the indicated number of samples.

read_other_buffer

Reads the specified number of samples from the other channels at the indicated sampling rate.

read_other_write_other_buffer

Reads from the specified encoder input channels and writes to the PWM output channels at the given sampling rate, for the indicated number of samples.

read_write_buffer

Reads from the specified input channels and writes to the specified output channels at the given sampling rate, for the indicated number of samples.

write_analog_buffer

Writes the specified samples to the analog channels at the indicated sampling rate.

write_buffer

Writes the specified samples to the selected channels at the indicated sampling rate.

write_digital_buffer

Writes the specified samples to the digital channels at the indicated sampling rate.

write_other_buffer

Writes the specified samples to the other channels at the indicated sampling rate.

write_pwm_buffer

Writes the specified samples to the PWM channels at the indicated sampling rate.

Task I/O Functions

The task functions are used for performing I/O in the background at a fixed sampling rate. They are useful for applications such as control systems or streaming of data. Tasks are first created using one of the task_create methods. The task instance that is returned is then used to start and stop the task and to generate or collect samples using the task.

The functions for creating tasks are as follows. For the operations that may be performed on tasks, refer to the quanser.hardware.task class.

task_close_all

Deletes all tasks associated with the board.

task_create_analog_reader

Creates a task to read the specified analog channels.

task_create_analog_reader_analog_writer

Creates a task to read the specified analog channels and write to the specified analog channels.

task_create_analog_writer

Creates a task to write to the specified analog channels.

task_create_digital_reader

Creates a task to read the specified digital channels.

task_create_digital_reader_digital_writer

Creates a task to read the specified digital channels and write to the specified digital channels.

task_create_digital_writer

Creates a task to write to the specified digital channels.

task_create_encoder_reader

Creates a task to read the specified encoder channels.

task_create_encoder_reader_pwm_writer

Creates a task to read the specified encoder channels and write to the specified PWM channels.

task_create_other_reader

Creates a task to read the specified other channels.

task_create_other_reader_other_writer

Creates a task to read the specified other channels and write to the specified other channels.

task_create_other_writer

Creates a task to write to the specified other channels.

task_create_pwm_writer

Creates a task to write to the specified PWM channels.

task_create_reader

Creates a task to read the specified channels.

task_create_reader_writer

Creates a task to read the specified channels and write to the specified channels.

task_create_writer

Creates a task to write the specified channels.

task_stop_all

Stops all tasks associated with the board.

Watchdog Functions

The watchdog functions are used to control the watchdog timer on data acquisition cards that support one. Once a watchdog timer is started, it must be reloaded before it expires to prevent the watchdog from expiring. When it expires, the outputs of the card are reset to the watchdog expiration states and the card enters the watchdog state. In the watchdog state, outputs cannot be written. The watchdog state must be cleared in order to resume writing to the outputs of the card. Watchdogs are used for safety considerations as they can detect when a software failure occurs because the watchdog does not get reloaded before expiry.

The watchdog functions are as follows:

watchdog_clear

Clears the watchdog state.

watchdog_is_expired

Indicates whether the watchdog timer has expired.

watchdog_reload

Reloads the watchdog timer.

watchdog_set_analog_expiration_state

Sets the watchdog expiration state of the specified analog channels.

watchdog_set_digital_expiration_state

Sets the watchdog expiration state of the specified digital channels.

watchdog_set_other_expiration_state

Sets the watchdog expiration state of the specified other channels.

watchdog_set_pwm_expiration_state

Sets the watchdog expiration state of the specified PWM channels.

watchdog_start

Starts the watchdog timer.

watchdog_stop

Stops the watchdog timer.

Interrupt Functions

The interrupt functions are used to monitor interrupts from the card. Interrupts may be polled directly or a monitor may be created to track interrupts in the background. Monitors are first created using one of the monitor_create_interrupt_reader method. The monitor instance that is returned is then used to start and stop the monitor and to read the interrupt states using the monitor.

The interrupt functions are as follows. For the operations that may be performed on monitors, refer to the quanser.hardware.monitor class.

monitor_close_all

Deletes all monitors associated with the board.

monitor_create_interrupt_reader

Creates a monitor to read the specified interrupt channels.

monitor_stop_all

Stops all monitors associated with the board.

poll_interrupt

Polls the specified interrupt sources.

 

navigation bar