Skip to Main Content Skip to Search
Product Documentation

UDP Receive - UDP Receive block

Library

xPC Target Library for UDP

Description

The Receive block has two output ports. The first port is the output of the received data as a vector of uint8 while the second one is a flag indicating whether any new data has been received. This port outputs a value of 1 for the sample when there is new data and a 0 otherwise. The default behavior of the Receive block is to keep the previous output when there is no new data. You can modify this behavior by using the second port to flag when there is new data.

Regardless of the data type, this block returns its data as a byte stream (represented as a vector of uint8 values). Use the UDP Unpack block to convert from the vector of uint8 values to the signal data type. See the UDP Data Streaming Demo for a demonstration of how to use the UDP Unpack block to extract your data.

Block Parameters

IP address to receive from

Enter a valid IP address as a dotted decimal string. For example, 10.10.10.3. You can also use a MATLAB expression that returns a valid IP address as a string.

Can be left with the default value of 0.0.0.0. This accepts all UDP packets from any computer. If set to a specific IP address, only packets arriving from that IP address are received.

IP port to receive from

Receiver port that the block accepts data from. The other end of the communication sends data to the port specified here. This value must match the Remote IP port to send to parameter of the UDP Send block

Output port width

Width of the acceptable packets, in bytes. You can obtain this number when designing the other side (send side) of the communication. If you select Allow variable length packets, this parameter defines the maximum length of the message.

If Allow variable length packets is cleared, the block receives only packets of Output port width length. It discards the other packets.

Allow variable length packets

Select this check box to enable the reception of variable length messages. The value of Output port width defines the maximum length of the message. If this check box is selected, the first output port sends the actual data. If the port size is less than the size of the actual data, the block sends up to the allowed length of data. It discards the extra data. The UDP Receive block does not return the number of discarded bytes. The behavior of the second output port depends on what environment the block is in:

  • If the block is in the xPC Target environment, the second output port sends the length of the original incoming message, m.

  • If the block is in the Simulink environment, the second output port sends the size of the first output port +1.

If this check box is cleared (default), the first output port contains the actual data, and the second output port contains:

  • 1, if the block receives the packet.

  • 0, if the block does not receive the packet.

Sample time

You can set this parameter to -1 for an inheritable sample time, but you should set this parameter to some specific (small) value to eliminate chances of dropped packets. This is especially true when you are using a small base sample time.

See Also

UDP Send

UDP Unpack

UDP Data Streaming Demo

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS