Main Content

UDP String Data and Message Handling

This example shows how to transfer text data by using the UDP communication protocol and shows how to store the incoming messages in a FIFO queue.

The model receives randomly distributed text messages containing textual color description by using the Stream Input block. The model converts the textual color description into corresponding numeric color code. A FIFO queue stores the color codes. The model sequentially displays the received colors at a sample rate that is perceptible to the human eye.

TheMessage generatorsubsystem simulates a remote device by randomly sending color text messages to the model. These messages provide input data for the example.

Run Model in Connected IO Mode

  1. To switch toConnected IOmode if needed, on the桌面实时tab, selectMode>Connected IO.

  2. To start the real-time execution, clickRun in Real-Time.

Run Model in Run in Kernel Mode

  1. To switch toRun in Kernelmode if needed, on the桌面实时tab, selectMode>Run in Kernel.

  2. To start the real-time execution, clickRun in Real-Time.

The model builds, connects to Simulink inRun in Kernelmode, and starts.

Open the Model

These commands open the model and suppress warning about board not installed.

w = warning('off','sldrt:blkgui:boardnotonlist'); open_system(fullfile(matlabroot,'toolbox','sldrt','sldrtexamples','sldrtex_stringmessage')); warning(w);

Close Open Scopes

close_system(find_system(gcs ,'BlockType',“范围”));

Clean Up Model

clear closeallbdcloseall

See Also