TCP Receive
Receive data over TCP/IP network from remote host
Add-On Required: This feature requires the Simulink Coder Support Package for NXP FRDM-K64F Board add-on.
Libraries:
Simulink Coder Support Package for NXP FRDM-K64F Board
Description
The TCP Receive block receives data from a remote host or other target
hardware over a wired network. When you set Connection mode to
Server
, you must provide the Local IP Port.
The Local IP Port acts as the listening port of the TCP/IP server.
When you set Connection mode to Client
, you must
provide the Remote IP Address and the remote IP
Port of the server from which to receive the data.
The block has two output ports, Data and Status. At each sample time, the Data port outputs data as a vector of the size specified in the Data size (N) parameter.
The Status port outputs 0
, when the length of the data
received is greater than or equal to the length specified in the Data size (N) parameter. Otherwise, it outputs 1
,
indicating that no new data is available.
During simulations without the hardware, the block emits zeros.
Note
In some cases, the antivirus or firewall may block the TCP traffic. If so, configure the antivirus or firewall to allow the traffic for a specific IP port number.
The block accepts data either in blocking mode or in non-blocking mode.
In blocking mode, the model blocks the execution while it waits for the requested data to be available.
At time step 1, the block requests four data values, and the TCP/IP receive buffer gets four data values. The execution runs.
At time step 2, the block requests for data again, but the TCP/IP receive buffer gets only three data values. The execution pauses until the buffer receives the fourth data value or the time-out value elapses. Then, the execution resumes.
At time step 3, the block requests for data, and the buffer receives five data values. The block returns the first four data values, and the remaining data value is used in the next receipt cycle.
In non-blocking mode, the model runs continuously.
At time step 1, the block requests data, and the buffer gets four data values. The block changes the Status port value to 0, indicating that new requested data is available. The Data port, at this point, contains the newly received data values. The block resets the Data port value to 0.
At time step 2, the block requests data again, but the buffer gets 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 to 1, indicating that there is no new data. All values on the Data port become 0. The buffer, at this point, has three data values. However, during this phase, the execution does not stop unlike in the blocking mode.
At time step 3, the buffer has five data values, and the block returns the first four data values in the order received and changes the Status port value to 0. The remaining data value is used in the next receipt cycle.
Ports
Output
Parameters
Version History
Introduced in R2017b