UDP block for simulink

1 visualizzazione (ultimi 30 giorni)
Judah
Judah il 8 Ago 2022
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

Risposte (0)

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by