Documentation

UDP Receive

Receiveuint8vector as UDP message

Library

Sources

dspsrcs4

Description

The UDP Receive block receives UDP packets from an IP network port and saves them to its buffer. With each sample, the block outputs the contents of a single UDP packet as a data vector. The local IP port number on which the block receives the UDP packets is tunable in the C/C++ generated code.

The generated code for this block relies on prebuilt.dllfiles. You can run this code outside the MATLAB®environment, or redeploy it, but you must account for these extra.dllfiles when doing so. ThepackNGofunction creates a single zip file containing all of the pieces required to run or rebuild this code. For more details, seeHow To Run a Generated Executable Outside MATLAB.

Parameters

Local IP port

Specify the IP port number on which to receive UDP packets. This parameter is tunable in the C/C++ generated code but not tunable during simulation. The default is25000. The value can be in the range [1 65535].

Note

On Linux®, to set the IP port number below 1024, run MATLAB with root privileges. For example, at the Linux command line, enter:

sudo matlab

Remote IP address ('0.0.0.0'to accept all)

Specify the IP address from which to accept packets. Entering a specific IP address blocks UDP packets from other addresses. To accept packets from any IP address, enter'0.0.0.0'. This value defaults to'0.0.0.0'.

Receive buffer size (bytes)

Make the receive buffer large enough to avoid data loss caused by buffer overflows. This value defaults to8192.

Maximum length for Message

Specify the maximum length, in vector elements, of the data output vector. Set this parameter to a value equal or greater than the data size of a UDP packet. The system truncates data that exceeds this length. This value defaults to255.

If you disableOutput variable-size signal, the block outputs a fixed-length output the same length as theMaximum length for Message.

Data type for Message

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 touint8.

Output variable-size signal

If your model supports signals of varying length, enable theOutput variable-size signalparameter. This checkbox defaults to selected (enabled). In that case:

  • The output vector varies in length, depending on the amount of data in the UDP packet.

  • The block emits the data vector from a single unlabeled output.

If your model does not support signals of varying length, disable theOutput variable-size signalparameter. In that case:

  • The block emits a fixed-length output the same length as theMaximum length for Message.

  • If the UDP packet contains less data than the fixed-length output, the difference contains invalid data.

  • The block emits the data vector from theMessageoutput.

  • The block emits the length of the valid data from theLengthoutput.

  • The block dialog box displays theData type for Lengthparameter.

在这两种情况下,excee截断数据块ds theMaximum length for Message.

Blocking time (seconds)

For each sample, wait this length of time for a UDP packet before returning control to the scheduler. This value defaults toinf, which indicates to wait indefinitely.

Note

This parameter appears only in the Embedded Coder®UDP Receive block.

Sample time (seconds)

Specify how often the scheduler runs this block. Enter a value greater than zero. In real-time operation, setting this option to a smaller value reduces the likelihood of dropped UDP messages. This value defaults to a sample time of 0.01 s.

Extended Capabilities

See Also

System Objects

Blocks

Introduced in R2010a

Was this topic helpful?