Receive binary data over serial port
Instrument Control Toolbox
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.
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
means new data is available and if the Status port
0 it means no new data is available.
Configure your serial port parameters before you specify the source block parameters.
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.
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.
Anything entered in the header is treated as a character. If
you want to specify numbers, you need to use the corresponding ascii
characters for them. For example, to specify
you can enter
() in the field. Note that single
quotes are also treated as characters. You can use the corresponding
ascii characters for the numbers between 32 and 126.
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
Specify the output data size, or the number of values that should
be read at every simulation time step. The default size is
Specify the output data type to receive from the block. You can select from the following values:
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
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.
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.
Specify a custom value for the block to output when it does
not receive current data. The default value is
The custom value can be scalar or value equal to the size of Data
that it receives (specified by Data size field).
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