UDP in - Ethernet UDP input mailbox

The UDP input mailbox block allows receiving up to 1024 bytes of data via Ethernet using the UDP protocol (in SDK versions prior to 2025.2, the size limit is 8 byte). To send data, the UDP output mailbox should be used.

The block returns the data received via UDP on a specified port, formatted as a vector. The Signal decoding format parameter defines the data type of each element, and the Number of signals parameter defines the length of the output vector. The data can be interpreted as one of the following types: int8, int16, int32, uint8, uint16, uint32, float32, or float64.

Example: if Signal decoding format is set to uint32 (4 bytes) and Number of signals is 100, then:

  • Size of the UDP data = 4 × 100 = 400 bytes
  • Output = vector of 100 uint32 elements

Simulink block

Signal specification

  • The first signal returns the data received via UDP, formatted as a vector. The Signal decoding format parameter defines the data type of each element, and the Number of signals parameter defines the length of the output vector.
  • The second signal is the data valid output. It is set to 1 each time new data are available.

Parameters

  • Ethernet port number: sets the port number on which data will be received.
  • Signal decoding format: defines the type of the data output (int8, int16, int32, uint8, uint16, uint32, float32, or float64).
  • Number of signals: specifies the vector size of the data output signal.
  • Byte order: defines the byte order in which the data will be read. (Little-endian or Big-endian)
  • Initial value: sets the initial value of the data output before any data are received.
Ethernet input mailbox Simulink dialog parameters

PLECS block

  • The first signal returns the data received via UDP, formatted as a vector. The Signal decoding format parameter defines the data type of each element, and the Number of signals parameter defines the length of the output vector.
  • The second signal is the data valid output. It is set to 1 each time new data are available.

Parameters

  • Ethernet port number: sets the port number on which data will be received.
  • Signal decoding format: defines the type of the data output (int8, int16, int32, uint8, uint16, uint32, float32, or float64).
  • Number of signals: specifies the vector size of the data output signal.
  • Byte order: defines the byte order in which the data will be read. (Little-endian or Big-endian)
  • Initial value: sets the initial value of the data output before any data are received.
Ethernet input mailbox Plecs dialog parameters

C++ functions

Standard functions

bool Eth_ConfigureInputMailbox(unsigned int mailboxId, unsigned int port, tEndianness endianness = LITTLE_ENDIAN, size_t msgLength = 4);Code language: C++ (cpp)

Configures an Ethernet UDP input mailbox.

Can only be called in UserInit().

Parameters

  • mailboxId:  the mailbox unique identifier. This ID must be unique throughout all ETH and CAN input/output mailboxes
  • port: the destination UDP port number to which the data will be sent
  • endianness: defines the bytes order. BIG_ENDIAN (most significant byte first) or LITTLE_ENDIAN (least significant byte first)
  • msgLength: size in bytes of the message, for best performance it is advised to keep it under 1024 bytes

Return value

  • Returns false if the maximum input mailboxes limit is exceeded or if the port was already assigned to another ETH input mailbox. Otherwise, returns true.
bool Eth_ConfigureInputMailboxInitialValue(unsigned int mailbox_id, void* data, size_t size);Code language: C++ (cpp)

Configures the initial value, for a given input mailbox, returned by the Eth_Read functions before any UDP message is received.

Can only be called in UserInit().

Parameters

  • mailboxId:  the mailbox unique identifier. This ID must be unique throughout all ETH and CAN input/output mailboxes
  • data: pointer to the default data which will be returned by Eth_Read before receiving any data in the mailbox
  • size: size in bytes of the data to copy. If the mailbox size is divisible by the size argument, the given data will be copied to the mailbox buffer until it is full

Return value

  • Returns false if the mailbox ID is invalid, or if the specified size is zero, exceeds the mailbox size, or is not divisible by the mailbox size. Otherwise, returns true.
int Eth_Read(unsigned int mailboxId, void* data, size_t size);Code language: C++ (cpp)

Reads the data received on a given Ethernet (UDP) input mailbox.

Can only be called in interrupt routine.

Parameters

  • mailboxId:  the mailbox unique identifier. This ID must be unique throughout all ETH and CAN input/output mailboxes
  • data: pointer to the buffer where data read from Ethernet (UDP) will be stored
  • size: number of bytes to read (must match the msgLength configured for the mailbox)

Return value

  • Returns 1 if new data was copied to the data buffer.

Legacy functions

bool Eth_ConfigureInputMailboxInitialValue(unsigned int mailboxId, unsigned int initialValue);Code language: C++ (cpp)
bool Eth_ConfigureInputMailboxInitialValue(unsigned int mailboxId, int initialValue);Code language: C++ (cpp)
bool Eth_ConfigureInputMailboxInitialValue(unsigned int mailboxId, float initialValue);Code language: C++ (cpp)

Configures the initial value, for a given input mailbox, returned by the Eth_Read functions before any UDP message is received.

Can only be called in UserInit().

Parameters

  • mailboxId:  the mailbox unique identifier. This ID must be unique throughout all ETH and CAN input/output mailboxes
  • initialValue: default data which will be returned by Eth_Read before data are received in the mailbox

Return value

  • Returns false if the mailbox ID is invalid, or if the initial value size exceeds the mailbox size, or is not divisible by the mailbox size. Otherwise, returns true.
int Eth_Read(unsigned int mailboxId, unsigned int &data);Code language: C++ (cpp)
int Eth_Read(unsigned int mailboxId, int &data);Code language: C++ (cpp)
int Eth_Read(unsigned int mailboxId, float &data);Code language: C++ (cpp)

Reads the data received on a given Ethernet (UDP) input mailbox.

Can only be called in interrupt routine.

Parameters

  • mailboxId:  the mailbox unique identifier. This ID must be unique throughout all ETH and CAN input/output mailboxes
  • data: pointer to the buffer where data read from Ethernet (UDP) will be stored

Return value

  • Returns 1 if new data was copied to the data buffer.