UDP Receive
Receive UDP packets from UDP host
Libraries:
STM32 Microcontroller Blockset /
STM32F7
STM32 Microcontroller Blockset /
STM32H7
Description
The UDP Receive block receives UDP packets from a UDP host. Use the block for stateless and connectionless data transmission.
With each sample, the block outputs the contents of a UDP packet as a (Nx1) array.
The block receives the packets on the port number specified in the
Local IP Port parameter from the IP address
specified in the Remote IP address (0.0.0.0 for accepting
all) parameter. To receive packets from all the sending
hosts, specify the remote IP address as 0.0.0.0. Match
the port number specified in the Local IP Port
parameter with the remote port number of the sending host.
You can choose to receive the UDP packets in blocking or non-blocking mode.
Note
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 the traffic for a specific IP port number.
Ports
Output
At each sample time, the port outputs the contents of a packet received as a data vector of the size that you specify in the Data size (N) parameter.
Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean
At each sample time, the port outputs
0 when the length of data
received is greater than or equal to the length
specified in the Data size
(N) parameter. A value of
0 indicates that the requested
data is received at the given time step.
Otherwise, it outputs a nonzero value, indicating
that no new data is available.
Data Types: uint16
Parameters
Specify the port number of the application from which you want to receive the packets. Match the local port number with the remote port number of the sending host.
Specify the IP address of the remote host from which
the block receives packets. To receive packets from
all the sending hosts, specify
0.0.0.0.
Select the data type in which the block receives the elements from the sending host. The size of each element depends on its data type.
Specify the number of elements that you want to receive in each packet. The data size must be scalar values.
on— When you select this parameter, the read operation runs in the Blocking mode. The read operation is blocked while waiting for the requested data to be available. If data is available, theDataport outputs data. If data is not available, theDataport waits for data.A task overrun occurs if the target hardware is still waiting for the data to be available when the next read operation is scheduled to begin.
To fix overruns:
Increase the time step by using the Sample time parameter.
Reduce the length of data requested by using the Data size (N) parameter.
off— When you clear this parameter, the read operation runs in the Non-blocking mode. When reading data, if data is not available, theDataport contains the packet received in the previous time step. In this mode, the block does not wait for the requested data to be available.
Select this option to display the error status during data transmission.
When you select the Output error status parameter, the block configures an output port. The port on the block is labeled as Status, indicating that the block outputs the status of the read operation at the output port.
When you specify this parameter
as-1, Simulink® determines
the best sample time for the block based on the
block context within the model.
Receive UDP Packets
This example describes the values at the output ports when the length of the packets received is less than, greater than, or equal to the length of requested data.
Length of UDP packet received = Data size (N): The
Dataport outputs the packet as a data vector of the size specified in the Data size (N) parameter.The
Statusport outputs0, indicating that the requested data is received.Suppose that the Data size (N) parameter specified is 4 and the length of the packet received is also 4.
In this case, the
Dataport outputs a data vector of size 4 filled with the elements of the packet.The value at the
Statusport is0.
Length of UDP packet received < Data size (N): The
Dataport outputs the packet as a data vector of the size specified in the Data size (N) parameter. All the empty spaces in the vector are filled with random values.The
Statusport outputs a nonzero value, indicating that no new data is received.Suppose that the Data size (N) parameter specified is 4 and the length of data received is 3 bytes.
In this case, the
Dataport outputs a data vector of size 4. The first three elements in the vector are the elements from the received packet. The remaining space is filled with a random value.The
Statusport outputs a nonzero value.
Length of UDP packet received > Data size (N): The
Dataport outputs a data vector of the size specified in the Data size (N) parameter. The vector contains only the first N elements from the packet. The remaining elements are dropped.The
Statusport outputs0, indicating that the requested data is received.Suppose that the Data size (N) parameter specified is 4 and the length of data received is 5 bytes. In this case, the
Dataport outputs a data vector of size 4. The vector contains only the first four elements from the received packet. The remaining element is dropped. The value at theStatusport is0.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2017a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)