How to send data from Simulink using the "UDP Send" block and receive the data in MATLAB?
10 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2023-4-11
回答: MathWorks Support Team
2023-4-18
I would like to send data from a Simulink model and receive data in MATLAB with a script in the same MATLAB session. How can I achieve that using the "UDP Send" block (from the Instrument Control Toolbox) in Simulink and the "udpport" object in MATLAB?
采纳的回答
MathWorks Support Team
2023-4-11
To receive data in MATLAB, the local IP and local port number set in the "udpport" object have to match the remote IP and remote port number of the send block in Simulink respectively. To run the Simulink model and the MATLAB code on the same computer, you could use "127.0.0.1" for both, which is the loopback address.
The following procedure demonstrates the workflow of reading data asynchronously from an input buffer using the "BytesAvailableFcn" event callback, such that data is only read when a specified number of bytes become available. Please note that the files attached are needed in order to run this example, which has been verified in MATLAB R2022b.
1) Run the MATLAB script "data_receive_callback.m", which creates a "udpport" object bound to a UDP socket and starts listening.
2) Run the Simulink model "data_send_model.slx" to send data. The MATLAB Command Window should then display the data received.
3) When you finish, disconnect and clear the "udpport" connection through the following:
clear u;
Please be aware that the "udpport" object is introduced since MATLAB R2020b. More information on the object can be found here:
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!