Receive data over TCP/IP from specified remote machine
Instrument Control Toolbox
The TCP/IP Receive block configures and opens an interface to a specified remote address using the TCP/IP protocol. The configuration and initialization occur once at the start of the model's execution. During the model's run time, the block acquires data either in blocking mode or nonblocking mode.
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 either one or two output ports, based on your selection of blocking or nonblocking mode. If you select blocking mode then 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 nonblocking mode, the Status port indicates if the block has received new data.
Use the TCP/IP Receive block to read streaming data over a TCP/IP network, using the Instrument Control Toolbox functionality in Simulink.
Use the Source Block Parameters dialog box to select your communication parameters.
Enter the IP address, name, or the Web server address of the machine from which you need to receive data. This field is empty by default.
Enter the remote port on the remote machine you need to connect
to. The default port value is
80. Valid port values
Click this button to:
Check if the specified remote address is correct.
Establish connection with the specified remote address and port.
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 using binary or binblock format with more than 8 bits,
you can specify the instrument's byte order for the data. Your options
Big Endian or
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. The following diagrams show the difference between receiving data using blocking mode and nonblocking mode.
In this example, you start the simulation at time (t=0) and specify the amount of data to receive as 4 (set in the Data size field of the TCP/IP Receive Block Parameters dialog box). Once the simulation starts, the data is acquired asynchronously in a FIFO buffer.
The blocking mode simulation occurs like this:
At time step 1: The Simulink software requests data and the buffer has four values available. The block fulfills the request without interrupting the simulation. The block resets the buffer value to 0.
At time step 2: The Simulink software requests data again, and the buffer has only three values, therefore it blocks the simulation until it receives the fourth value. When the block receives the fourth value, it fulfills the request and resumes the simulation. The block resets the buffer value to 0.
At time step 3: When Simulink software requests data, the block has five values and it returns the first four that it received and resets the buffer to 1.
If the requested data is not received within the amount of time specified in the Timeout field (of the TCP/IP Receive Block Parameters dialog box), a Simulink error occurs and the simulation is stopped.
Note: In blocking mode, if you have more than one TCP/IP model on your computer, ensure that the Receive block is receiving data. If it is not, then your model might error out. You can avoid this by either changing the block to Nonblocking mode or by resetting the block's Priority.
Here the simulation is not blocked and runs continuously.
At time step 1: The Simulink software requests
data and the buffer has four values available, the block fulfills
the request and changes the
Status port value to
indicating that new data is available. The
at this point contains the newly received values. The block resets
the buffer value to 0.
At time step 2: The Simulink software requests
data again, and the buffer has only three values. The block cannot
return a value of 3 because the data size is specified as 4. Therefore,
the block sets the Status port value
0, indicating that there is no new data. The Data port contains the previously received
value, and the buffer is at three (the number of values it received
since the last request was fulfilled).
At time step 3: When the Simulink software requests
data here, the buffer now has five values and it returns the first
four in the order received and changes the Status port
Specify the amount of time that the model will wait for the
data during each simulation time step. The default value is
This field is disabled if you did not select Enable
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