I/O Driver Blocks

The Simulink® Real-Time™ environment is a solution for prototyping and testing real-time systems using a desktop computer. To support this solution, the software allows you to add I/O blocks to your model. The blocks of the Simulink Real-Time library provide a particular function of an I/O module. By using I/O blocks in your model, you can generate executable code tuned specifically to your I/O requirements.

You add I/O driver blocks to your Simulink model to connect your model to I/O modules (I/O boards). These I/O modules then connect to the sensors and actuators in the physical system.

Speedgoat I/O Modules

Speedgoat real-time target machines are available with various I/O modules. See Speedgoat I/O Connectivity.

Third-Party Driver Blocks

In addition to the blocks contained in the Simulink Real-Time library, you can also use third-party driver blocks in your Simulink Real-Time model. The description of these blocks is beyond the scope of the Simulink Real-Time documentation. See the provider of the third-party driver blocks for information on those boards and driver blocks.

I/O Driver Block Library

A driver block does not represent an entire board, but an I/O section supported by a board. Therefore, the Simulink Real-Time library can have more than one block for each physical board. I/O driver blocks are written as C-code S-functions (noninlined S-functions). The source code for the C-code S-functions is included with the Simulink Real-Time software.

Note, if your model contains I/O blocks, take I/O latency values into account for the model sample time. To find latency values for a board supported by the Simulink Real-Time block library, consult the vendor data sheet. To find a link to the vendor website, see:

To find latency values for Speedgoat boards, contact Speedgoat technical support.

The Simulink Real-Time system supports PCI and ISA (PC/104) buses. If the bus type is not indicated in the driver block number, determine the bus type of the block by examining the block parameter dialog box. The last parameter is either a PCI slot, for PCI boards, or a base address, for ISA (PC/104) boards.

You can open the I/O device driver library with the MATLAB® command slrtlib. The library slrtlib contains sublibraries grouped by the type of I/O function they provide.

This library also contains the following blocks:

  • Simulink Real-Time Driver Examples — When you double-click this block, the Demos tab in the MATLAB Help Navigator opens, displaying the Simulink Real-Time examples and example groups.

  • Help for Simulink Real-Time — When you double-click this block, the Simulink Real-Time roadmap page is displayed. You can access the Simulink Real-Time documentation with this block.


The Simulink Real-Time documentation describes only the Simulink Real-Time blocks. It does not describe the actual board. Refer to the board manufacturer documentation for information about the boards.

When you double-click one of I/O block groups, the sublibrary opens, displaying a list grouped by manufacturer. Double-clicking one of the manufacturer groups displays the I/O device driver blocks for the specified I/O functionality (for example, A/D, D/A, Digital Inputs, and Digital Outputs).

When you double-click one of the blocks, a Block Parameters dialog box opens, allowing you to enter system-specific parameters. Parameters typically include

  • Sample time

  • Number of channels

  • Voltage range

  • PCI slot (PCI boards)

  • Base address (ISA/104 boards)

Memory-Mapped Devices

Simulink Real-Time reserves a 112 kB memory space for memory-mapped devices in the address range:

C0000 - DBFFF

Drivers for some memory-mapped devices, such as the Softing CAN-AC2-104 board, support an address range higher than the range that Simulink Real-Time supports. Specify an address range supported by both the device driver and the Simulink Real-Time software.

ISA Bus I/O Devices

There are two types of ISA boards:

  • Jumper addressable ISA cards

  • PnP (Plug and Play) ISA cards

The Simulink Real-Time software only supports jumper addressable ISA cards (non-PnP ISA boards) where you have to set the base address manually.

PCI Bus I/O Devices

The Simulink Real-Time I/O library supports I/O boards with a PCI bus. During the boot process, the BIOS creates a conflict-free configuration of base addresses and interrupt lines for the PCI devices in the target system. You do not need to define base address information in the dialog boxes of the drivers.

PCI device driver blocks have an additional entry in their dialog boxes. This entry is called PCI Slot (-1 Autodetect) and allows you to use several identical PCI boards within one target system. This entry uses a default value of -1, which allows the driver to search the entire PCI bus to find the board. If you specify a single number, X, greater than 0, the driver uses the board in bus 0, slot X. When more than one board of the same type is found, you must use a designated slot number and avoid the use of autodetection. For manually setting the slot number, you use a number greater than or equal to 0. If the board cannot locate this slot in the target computer, your real-time application will generate an error message after downloading.

To set PCI Slot (-1 Autodetect) to a value equal to or greater than 0, you must identify which board you want on the target computer. To identify the board, find the manufacturer identification number (Vendor ID) and board identification number (Device ID) of the boards supported by the I/O library. When the target is booted, the BIOS is executed and the target computer monitor shows parameters for the PCI boards installed on the target computer. For example:

Bus Number

Device Number

Function Number

Vendor ID

Device ID

Device Class







IDE controller







Serial bus controller







Unknown PCI device







Display controller


In this example, the third line indicates the location of the Measurement Computing™ PCI-DIO48 board. This location is known since the Measurement Computing vendor ID is 0x1307 and the device ID is 0xb. In this case, you can see that the Measurement Computing board is plugged into PCI slot 11 (Device Number). Enter this value in the dialog box entry in your I/O device driver for each model that uses this I/O device.

Simulink Real-Time I/O Driver Structures

Properties for Simulink Real-Time I/O drivers are defined using the parameter dialog box associated with each Simulink block. However, for more advanced drivers, the available fields defined by text boxes, check boxes, and pull-down lists are inadequate to define the behavior of the driver. In such cases, you must provide a more textual description to indicate what the driver has to do at run time. Textual in this context refers to a programming-language-like syntax and style.

The Simulink Real-Time software currently uses a character vector description contained in message structures for the conventional RS-232, GPIB, CAN (initialization), and the general counter drivers (AMD9513).

What Is a Message Structure?

A message structure is a MATLAB array with each cell containing one complete message (command). A message consists of one or more statements.

First MessageSecond MessageThird Message

Syntax of a Message Statement

Each statement in a message has the following format:

Structure_name(index).field_name = <field character vector or value>

The driver defines the field names. Enter them with upper- and lowercase letters as defined. However, you can specify your own structure name and enter that name into the driver parameter dialog box.

Creating a Message Structure

You could enter the message structure directly in the edit field of the driver parameter dialog box. But because the message structure is a large array, direct entry becomes cumbersome easily.

A better way is to define the message structure as a variable in the MATLAB workspace and pass the variable name to the driver. For example, to initialize an external A/D module and acquire a value during each sample interval, create a script file with the following statements:

Message(1).senddata='InitADConv, Channel %d'

Message(2).senddata='Wait and Read converted Value'

This approach is different from other Simulink Real-Time driver blocks:

  • The script containing the definition of the message structure has to be executed before the model is opened.

    After creating your Simulink model and message script, set the preload function of the Simulink model to load the script file the next time you open the model. In the Command Window, type

    set_param(gcs, 'PreLoadFcn', 'script_name')
  • When you move or copy the model file to a new folder, you must also move or copy the script defining the message structure.

During each sample interval, the driver block locates the message structure, interprets the messages, and executes the command defined by each message.

Specific Drivers and Structures

For detailed information on the fields in a message structure, see the following topics:

Simulink Real-Time Support and SimState

You can save complete model simulation states while simulating, on a development computer, a Simulink model that contains some Simulink Real-Time blocks. The software does not support this behavior when executing such a model on the target computer.

For this operation, set the Save complete SimState in final state check box in the Data Import/Export pane of the Configuration Parameters dialog box. If your model contains the following blocks, you cannot save complete model simulation states while simulating on the development computer.

  • ASCII Encode

  • ASCII Decode

  • Async Buffer Read

  • Async Buffer Write

  • Baseboard Serial

  • Baseboard Serial F

  • Bit Packing (Utilities library)

  • Bit Unpacking (Utilities library)

  • Byte Packing (Utilities library)

  • Byte Unpacking (Utilities library)

  • Commtech Fastcom® 422/2–PCI

  • Commtech Fastcom 422/2–PCI F

  • Commtech Fastcom 422/2–PCI-335

  • Commtech Fastcom 422/2–PCI-335 F

  • Commtech Fastcom 422/4–PCI-335

  • Commtech Fastcom 422/4–PCI-335 F

  • Condor® 1553 BC List

  • Create Ethernet Packet (Ethernet library)

  • FIFO bin read

  • FIFO ASCII read

  • FIFO write

  • Quatech® DSCP-200/300

  • Quatech DSCP-200/300 F

  • Quatech ESC-100

  • Quatech ESC-100 F

  • Quatech QSC-100

  • Quatech QSC-100 F

  • Quatech QSC-200/300

  • Quatech QSC-200/300 F

  • UDP Receive

  • UDP Send

To prevent these messages, clear the Save complete SimState in final state check box in the Data Import/Export node of the Configuration Parameters dialog box.

PWM and FM Driver Block Notes

In PWM and FM driver blocks, your control over the output frequency and duty cycle is not precise. Although the base frequency value is exact, the way the base frequency is specified affects the output frequency and duty cycle.

At the beginning of each sample time, the block reads the current input signal values. It then computes two unsigned 16-bit integers, n and m, from the signal values and the block parameters. During the sample time, the block holds the output signal:

  1. High for m cycles of the base frequency

  2. Low for the next n-m cycles

  3. High for the next m cycles

  4. . . .

For a base frequency b, this algorithm results in a rectangular output signal of frequency b/n and duty cycle m/n. Because m and n must be integers, it is not possible to provide a continuous range of output frequencies and duty cycles with perfect exactness.

For example, assume that you want to configure an FM block with a duty cycle (m/n) of 1/2. The input signal f to this block is a relative frequency that specifies an output frequency of b × f. However, m and n must be integers. Therefore, you cannot always find values of m and n (duty cycle m/n = 1/2) such that:

f = b/n
exactly and
n = 2 * m
exactly. You can find an exact match only when the input signal f equals 1/4, 1/6, 1/8, and so forth. The output frequencies for the intervening input signal f values are approximate. The errors are smaller as f approaches 0 and larger as f approaches 1.

To achieve the smallest margin of error, specify the largest possible base frequency. The fact that n and m must be 16-bit integers imposes a lower limit of:

b / (2161)

on the frequencies that can be generated using a given base frequency.

Driver Block Documentation

The typical Simulink Real-Time block documentation briefly describes the supported board, then describes the parameters for each of the blocks that support the board. Included in the documentation for each board is a board characteristics table. Board characteristics tables can include the following information:

Board nameName of the board supported by the blocks. For example, National Instruments® PCI-6221.
ManufacturerManufacturer of the board. For example, National Instruments.
Bus typeBus that is used by the board. For example, PCI or ISA (PC/104).
Access methodWhether the board is memory mapped or I/O mapped.
Multiple block instance supportWhether you can use multiple blocks for the same function on the same board. For example, different blocks for different channels of an A/D device.
Multiple board supportWhether you can use multiple boards of the same type in one real-time application.
Was this topic helpful?