User`s guide
User Datagram Protocol (UDP)
3-17
Note Unreliable is used in the sense of “not guaranteed to succeed” as
opposed to “will fail a lot of the time.” In practice, UDP is quite reliable as long
as the receiving socket is active, and is processing data as quickly as it arrives.
Why UDP?
UDP was chosen as the transport layer for xPC Target precisely because of its
lightweight nature. Since the primary objective of an application running in
the xPC Target framework is real-time, the lightweight nature of UDP ensures
that the real-time application will have a maximum chance of succeeding in
real-time execution. Also, the datagram nature of UDP is ideal for sending
samples of data from the Simulink/RTW generated application. Since TCP is
stream oriented, separators between sets of data will have to be used for the
data to be processed in samples. It is easier to build an application to deal with
unreliable data than it is to decode all of this information in real-time. Also, if
the application is unable to process the data as quickly as it arrives, the
following packets can just be ignored and only the most recent packet can be
used.
Communication can involve a packet made up of any Simulink data type
(
double, int8, int32, uint8, etc.), or a combination of these. xPC Target
provides blocks for combining various signals into one packet (packing), and
then transmitting it. Also, xPC Target provides blocks for splitting a packet
(unpacking) into its component signals which can then be used in a Simulink
model. The maximum size of a packet is limited to about 500 bytes.
UDP Communication Setup
The infrastructure provided in the xPC Target Library for UDP communication
consists mainly of two blocks — a Send block and a Receive block. These blocks
may be found in the xPC Target Library available from the Simulink Library
under
xPC Target, or you can access then form the MATLAB command line,
by typing
xpclib
The blocks are located under the UDP heading in the library. The Send block
takes as input a vector of type
uint8, which it sends. This is limited to a length
of about 500 bytes (i.e., a 1x500 vector). Similarly, the Receive block outputs a