Why I am unable to read data into Simulink using "UDP Receive" blocks on my Windows PC?

28 visualizzazioni (ultimi 30 giorni)
My Simulink model is running on a Windows PC. The goal is to exchange data with an external sensor connected to my PC via Ethernet. To ensure low latency, I chose the UDP protocol.
I am able to send UDP packets to the sensor from Simulink using the "UDP Send" block, but I don't receive any data in Simulink using the "UDP Receive" block. How can I resolve this?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 22 Set 2023
When using UDP communication in your Simulink model running on a desktop PC, make sure to use the correct UDP Receive and UDP Send blocks that support UDP communication for desktop. These can be from the following three toolboxes:
Do not use any other UDP blocks, as they are designed for external hardware purposes.
Most likely, the incoming UDP packets are blocked by antivirus software or a firewall. You can try to temporarily disable those and see if it resolves the issue. Work with your IT team to allow MATLAB through the firewall. This page has some instructions:How do I configure Windows Defender Firewall for MATLAB to communicate with external hardware?
If using the correct UDP blocks & firewall settings still doesn't resolve the issue, here are a few more things to try out:
  • Make sure the network connection is set up correctly. You should be able to ping your external device's IP address using the Windows command line. You can use 'ipconfig' to see all the networks your computer is connected to and the respective IP addresses.
  • If your PC has multiple network interfaces (multiple Ethernet cards, USB-Ethernet converter, WiFi connection etc.), then the Windows network driver could be routing the UDP packet to the wrong network interface. You can try disabling all other network interfaces and just keep one of them active (the Ethernet which is used for host-target communication) and see if it resolves the issue.
  • You can try to configure the external device to send data to a different port (e.g., 25002 instead of 25001) and see if that resolves the issue.
  • Use a third-party tool such as Wireshark to monitor the network traffic on different network cards.
  • You can try the UDP Receive block from the Instrument Control Toolbox and uncheck "Enable blocking mode" to output the status. Check if the raw data are received successfully. Sometimes, data might be received successfully but interpreted incorrectly so it becomes zero.
  • The UDP block might not be not reading the data in the right format. In your UDP Receive block, you also need to specify the right type and buffer size to receive data correctly.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by