Receive UDP packets
Simulink Support Package for Android Devices / Communication
Receive UDP packets from another UDP host on the same local network.
The UDP Receive block has two output ports:
Data port outputs the UDP packet data
as an N-by-1 vector with a data type specified by the Data
type parameter. The
Size output emits
the current size of the data in the UDP buffer as
The data type of the block output,
Size port outputs a stream of zeros while UDP
Receive waits for new data to arrive. When new data arrives,
to a non-zero value.
If you simulate a model that contains the UDP Receive block
on your host computer, set Simulation > Normal,
Data outputs a zero for each step of the simulation
when no UDP packets are available. As a free-running application with
a shorter period than the real-time application running on the Android™ device,
many zeros can be produced from the output port
In other words, the free-running simulation outputs zeros while waiting
for the slower real-time application on the Android device to
If you are having trouble using UDP to communicate with a computer, investigate if antivirus or firewall software is blocking UDP traffic. If so, try to configure the software to allow UDP traffic for a specific IP port number.
- Local IP port
The number of the IP port on the local device, which can range from 1 – 65535. This value defaults to
25000. The “local device” is the board running the model.
- Data type
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
- Data size (N)
Set the number of data elements in each UDP packet. Match the data size used to create the UDP packets. This value defaults to
- Sample time
Specify how often this block reads the port buffer. Enter a value greater than zero. This value defaults to a sample time of
Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.