Receive UDP packets over IP network
Receive UDP packets from the local network. The block output, data, emits UDP packet data as a one-dimensional vector of a specified data type. The block output, size, emits the size the data in the UDP buffer.
The data type of the block output, Data
, depends on the
Data type parameter. The data type of the block
output, Size
, is uint16
.
While UDP Receive waits for new data to arrive, size emits a stream of zeros. When new data arrives, size changes to a non-zero value.
If you simulate a model that contains the UDP Receive block on your host computer (e.g., Simulation > Normal), and send UDP packets to that model from a board, the data output emits a disproportionately large number of zeros. This is because Simulink software simulates the model as a free-running application with a shorter period than the real-time application running on the board. In other words, the free-running simulation outputs zeros because it is waiting for the “slower” real-time application on the board to send data. If both applications were running on boards, this mismatch would not occur.
Note
If you are having trouble using UDP to communicate with a computer, investigate whether antivirus or firewall software might be blocking UDP traffic. If so, try configuring the software to allow UDP traffic for a specific IP port number.
The number of the IP port on the local device, which can range
from 1 to 65535. This value defaults to 25000
.
The “local device” is the board running the
model.
Set the data type of the vector elements in the Message output.
Match the data type with the data input used to create the UDP
packets. This option defaults to
uint8
.
Set the number of data elements in each UDP packet. Match the
data size used to create the UDP packets. This value defaults to
255
elements.
Specify how often this block reads the port buffer. Enter a
value greater than zero. This value defaults to a sample time of
0.01
seconds.
Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.