- Lower the sample time a bit more. Also, try increasing the buffer size in the UDP Receive block to handle more data at once.
- Test your setup with a direct Ethernet cable, without any switches or routers in between. Use a tool like Wireshark to see if packets are being lost.
- Ensure the PLC and Simulink are synchronized in terms of send/receive timing. For example, if the PLC sends data every 100 ms, set Simulink’s step size to 100 ms too. You might also want to add a small pause on the PLC after each packet is sent.
- Double-check your MATLAB Function block that looks for headers. Make sure it is not skipping valid packets because of parsing mistakes.
UDP communication between PLC S7-1200 and Simulink
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have a problem with UDP communication between a PLC S7-1200 and Simulink. From Simulink to the PLC I send 29 bytes of data (6 double values and an 8-bit array). The PLC sends the same amount of data back to Simulink every 100 ms, but with an additional 2-byte header that my MATLAB Function uses to detect the start of the packet. The issue is that many packets are lost (display missed), and the number of packets received from the PLC is much higher than the number of packets sent from Simulink (red frames). I would like to reduce packet loss and have a similar number of packets sent and received on both sides. I tried changing the step size and sample time in the UDP Receive block, and also changing the PLC send frequency, but it did not fix the issue. Reducing the PLC frequency only reduced the number of packets from Simulink proportionally. Any help or ideas on what could be the cause and how to improve the communication would be very appreciated.

0 Kommentare
Antworten (1)
Tridib
am 3 Nov. 2025 um 11:56
Bearbeitet: Tridib
am 3 Nov. 2025 um 12:11
UDP does not guarantee that messages will arrive, come in the right order, or not get repeated. It is normal to lose some packets, especially if you send them quickly or the network is busy. If you set the sample time for the UDP Receive block too high, you might miss packets because the buffer fills up. If it is too low, you could be checking too often, which is not efficient. Network issues like congestion, switches, or firewalls can also cause delays or lost packets.
Here are some troubleshooting steps which might help resolve the issue:
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Simulink PLC Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!