Main Content

Enable Blocking Mode in Receive and Send Blocks

The Enable blocking mode parameter allows you to wait until the requested data is available for the block to receive or wait until all the data sends. You can disable this option to allow your simulation to run continuously. This parameter is available in the following blocks:

Blocking Mode

The Enable blocking mode parameter is on by default.

Receive Blocks

If you enable blocking mode in the Serial Receive, TCP/IP Receive, and UDP Receive blocks, the simulation waits for the requested data to become available. The model waits for up to the amount of time specified by the Timeout parameter.

In this example, start the simulation at time t = 0 and specify the Data size as [4,1]. Once the simulation starts, the data is acquired asynchronously in a FIFO buffer.

Graph of Simulink buffer size versus time. Requests at different time steps are shown as vertical dotted lines.

The blocking mode simulation occurs in the following steps.

  • At time step 1: The Simulink® software requests data and the buffer size is four values. The block fulfills the request without interrupting the simulation. The block resets the buffer size value to 0.

  • At time step 2: The Simulink software requests data again, and the buffer size is only three values; therefore, the software 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 size value to 0.

  • At time step 3: When Simulink software requests data, the block has five values. It returns the first four that it received and resets the buffer size value to 1.

For each time step, if the requested data is not received within the amount of time specified in the Timeout field:

  • The Serial Receive block takes the action specified by the Action when data is not available parameter.

  • The TCP/IP Receive block outputs a value of 0.

Send Blocks

If you enable blocking mode in the Serial Send, TCP/IP Send, and UDP Send blocks, the simulation waits until the block sends complete data.

In this example, start the simulation at time t=0.

Time course of simulation, showing three separate blocks of data being sent at different time points.

At time step (T1), data output is initiated and simulation stops until the block of data (B1) is sent. After the data is sent, simulation resumes until time step (T2), where the block initiates another data output and simulation is blocked until the block of data (B2) is sent, and the simulation resumes.

Nonblocking Mode

Unselect the check box if you want the Enable blocking mode parameter to be off.

Receive Blocks

If you do not enable blocking mode in the Serial Receive, TCP/IP Receive, and UDP Receive blocks, the simulation runs continuously and 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.

Graph of Simulink buffer size versus time. Requests at different time steps are shown as vertical dotted lines.

Here the simulation is not blocked and runs continuously.

  • At time step 1: The Simulink software requests data and the buffer size is four values. The block fulfills the request and changes the Status port value to 1, indicating that new data is available. The Data port at this point contains the newly received values. The block resets the buffer size value to 0.

  • At time step 2: The Simulink software requests data again, and the buffer size is 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 0, indicating that no new data is available. The Data port contains the previously received value or 0, depending on the block, and the buffer size 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 size is now six values. The block returns the first four in the order received and changes the Status port value to 1.

Send Blocks

If you do not enable blocking mode in the Serial Send, TCP/IP Send, and UDP Send blocks, the simulation runs continuously.

Data output outpaces simulation speed

Time course of simulation, showing three separate blocks of data being sent at different time points.

In this scenario, the data output outpaces the simulation speed. Data output is initiated at the first time step (T1) and the corresponding block of data (B1) is sent to the specified remote address asynchronously. The simulation runs continuously in this mode.

Simulation speed outpaces data output

Time course of simulation, showing three blocks of data being sent one after the other.

In this scenario, the simulation speed outpaces the data acquisition.

  • At time step T1: The block of data (B1) is sent asynchronously.

  • At time step T2: The simulation is blocked until the block of data (B1) is sent completely. When B1 is completely sent, the new block of data (B2) is sent asynchronously, and the simulation resumes.

Note

Several factors, including network connectivity and model complexity, can affect the simulation speed, which can cause both nonblocking scenarios to occur within the same simulation.

See Also

| | | | |