Documentation Center

  • Trial Software
  • Product Updates

Serial Receive

Receive binary data over serial port

Library

Instrument Control Toolbox

Description

The Serial Receive block configures and opens an interface to a specified remote address using the Serial protocol. The configuration and initialization occur once at the start of the model's execution. The block acquires data during the model's run time.

    Note:   You need a license for both the Instrument Control Toolbox™ and Simulink® software to use this block.

This block has no input ports. It has one or two output ports based on your selection of blocking or nonblocking mode. If you select blocking mode, the block will have one output port corresponding to the data it receives.

If you do not select blocking mode, the block will have two output ports, the Data port and the Status port.

A First In, First Out (FIFO) buffer receives the data. At every time step, the Data port outputs the requested values from the buffer. In a nonblocking mode, the Status port indicates if the block has received new data. If the Status port displays 1 it means new data is available and if the Status port indicates 0 it means no new data is available.

Dialog Box

Use the Source Block Parameters dialog box to select your serial Receive block configuration options.

    Note:   Configure your serial port parameters before you specify the source block parameters.

Communication port

Specify the serial port that you will use to receive from. You have to select an available port from the list. By default, the Communication port field contains the text Please select a port... and you must change this to a valid port. If you have not configured a port, the block will prompt you to do so. You can select a port from the available ports and then configure the port using the Serial Configuration block. Each Serial Receive block must have a configured serial port. If you use multiple ports in your simulation, you must configure each port separately.

Header

Specify data that marks the beginning of your data block. The header indicates the beginning of a new data block and the simulation will disregard data that occurs before the header. The header data is not sent to the output port. Only data that occurs between the header and the terminator is sent to the output port. By default none or no header is specified.

Terminator

Specify data that marks the end of your data block. The terminator indicates the end of the data block and the simulation will account for any data that occurs after the terminator as a new data block. The terminator data is not sent to the output port. Only data that occurs between the header and the terminator is sent to the output port. By default <none> or no terminator is specified. Other available terminator formats are:

  • CR ('\r') — Carriage return

  • LF ('\n') — Line feed

  • CR/LF ('\r\n')

  • NULL ('\0')

Data size

Specify the output data size, or the number of values that should be read at every simulation time step. The default size is [1 1].

Data type

Specify the output data type to receive from the block. You can select from the following values:

  • single

  • double

  • int8

  • uint8 (default)

  • int16

  • uint16

  • int32

  • uint32

Byte order

When you specify a data type other than int8 or uint8, you can specify the byte order of the device for the binary data. Your options are BigEndian or LittleEndian.

Enable blocking mode

Specify if you want to block the simulation while receiving data. This option is selected by default. Clear this check box if you do not want the read operation to block the simulation.

If you enable blocking mode, the model will block the simulation while it is waiting for the requested data to be available. When you do not enable blocking mode, the simulation runs continuously. The block has two output ports, Status and Data. The Data port contains the requested set of data at each time step. The Status port contains 0 or 1 based on whether it received new data at the given time step.

Action when data is unavailable

Specify the action the block should take when data is unavailable. Available options are:

  • Output last received value — Block will return the value it received at the preceding time step when it does not receive data at current time step. This value is selected by default.

  • Output custom value — Block will return any user–defined value when it does not receive current data. You can define the custom value in the Custom value field.

  • Error — Block will return an error when it does not receive current data. This option is unavailable if you do not select blocking mode.

Custom value

Specify a custom value for the block to output when it does not receive current data. The default value is 0. The custom value can be scalar or value equal to the size of Data that it receives (specified by Data size field).

Block sample time

Specify the sample time of the block during the simulation. This is the rate at which the block is executed during simulation. The default value is 1 second.

Was this topic helpful?