The UDP Receive block configures and opens an interface to a specified remote address using the UDP 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 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, 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.
Use the Source Block Parameters dialog box to select your acquisition mode and to set other configuration options.
Specify 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.
Specify the remote port on the host you need to connect to. The default port value is 9090. Valid port values are 1 to 65535.
Specify the port to bind on the local machine. The default value is -1, which automatically binds to an available port.
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 [1 1].
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 are Big Endian or Little Endian.
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. If 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 UDP Receive Block Parameters dialog box). After 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 the 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 UDP Receive Block Parameters dialog box), a Simulink software error occurs and the simulation is stopped.
Note: In blocking mode, if you have more than one UDP 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 1, indicating that new data is available. The Data port 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, and the block cannot return it as data size is specified as 4. Therefore the block sets the Status port value to 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 has 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 it received and changes the Status port value to 1.
Specify the amount of time that the model will wait for the data during each simulation time step. The default value is inf (seconds). This field is unavailable if you have not enabled blocking mode.
Specify the sampling time of the block during simulation. The default value is 0.01 (seconds).