UDP block for simulink

3 次查看(过去 30 天)
Judah
Judah 2022-8-8
Hi,
I am trying to use judp.m as a reference for building a simple udp receive block for simulink.
In simulink I am using matlab function block with the code below:
I am not very familiar with coder and would be thankful if I can get assistance in getting this block fixed.
Thanks
function mssg = judp(targetPort)
timeout = 5000;
packetLength = 10;
coder.extrinsic('java.io.*')
coder.extrinsic('java.net.InetAddress')
coder.extrinsic('java.net.DatagramSocket')
coder.extrinsic('java.net.DatagramPacket')
socket = java.net.DatagramSocket(targetPort)
socket.setSoTimeout(timeout)
socket.setReuseAddress(1);
packet = java.net.DatagramPacket(zeros(1,packetLength,'int8'),packetLength);
socket.receive(packet);
socket.close;
mssg = packet.getData;
mssg = mssg(1:packet.getLength);
inetAddress = packet.getAddress;
sourceHost = char(java.net.InetAddress.inetAddress.getHostAddress);
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by