qc_script_console End of trail navigation bar

Table of Contents > QUARC > User's Guide

Accessing Hardware from Scripts

QUARC supports a variety of data acquisition cards, including Quanser's own Q4 and Q8 Hardware-in-the-Loop (HIL) boards, the National Instruments PCI-6259 and many more. Hardware connected to these boards can be accessed in scripts using the quanser.hardware.hil class. This API is designed such that it is trivial to switch between boards because the methods of the class are board-independent.

To open a board, use the static quanser.hardware.hil.open method of the quanser.hardware.hil class. It takes two arguments: the board type and a board identifier. The board type determines the type of board, such as a 'qpid_e', and the board identifier distinguishes between multiple boards of the same type, and is typically a string containing a numeric index, such as '0' or '1'. The board identifier is a string because some boards support the use of serial numbers or other identifying information.

A typical call to open a board would be:

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

The default board identifier is '0', so the second argument can be eliminated in that case:

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

Once a board is open, its methods may be used to configure the card, or read and write from the card. When the board is no longer being used, it should be closed using the close method as follows:

board.close;

The methods used to access hardware may be divided into different categories as listed below.

Configuration Functions

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.

For more details about the configuration functions, see the Configuration Functions of the quanser.hardware.hil class.

Immediate I/O Functions

The immediate I/O functions are used to do a single read and/or write from any channel of the board immediately. These functions are more suitable for control applications because they process one sample at a time.

For more details about the immediate I/O functions, see the Immediate I/O Functions of the quanser.hardware.hil class.

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. They reflect a 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.

If different channels such as analog, digital or encoder are to be read with the buffered I/O functions, it is more efficient to have a single read_buffer function rather than using multiple buffered I/O calls specific to each channel type.

For more details about the buffered I/O functions, see the Buffered I/O Functions of the quanser.hardware.hil class.

Task Functions

The task functions are used to read and/or write samples at a fixed rate in the background. These functions may be used for control or streaming, for example. The task functions can make use of hardware timers on the card for synchronization. On the Windows target, use of a hardware timebase results in better performance because hardware timebases are more efficient than the system timebase on the Windows target (at least for sample times faster than two milliseconds).

Similar to the buffered and immediate I/O HIL functions, if more than one channel type is being read using the task functions, it is more efficient to use a single generic reader task than a task for each channel type.

For more details about the task functions, see the Task I/O Functions of the quanser.hardware.hil class.

Watchdog Functions

The watchdog functions are used for implementing a watchdog timer on the data acquisition card. Watchdog timers are generally used for safety considerations because they allow a card to be put into a known state when software fails.

For more details about the watchdog functions, see the Watchdog Functions of the quanser.hardware.hil class.

Interrupt Functions

The interrupt functions are used for monitoring interupts on the data acquisition card. Interrupt sources are often very specific to a particular card.

For more details about the interrupt functions, see the Interrupt Functions of the quanser.hardware.hil class.

 

navigation bar