Real time Udp Send and Receive Block
Show older comments
I would like to send and receive data inside target computer(xpc target) by setting the Ip adresses of udp send and receive blocks as '127.0.0.1'. When I run the system as software in loop, It works.However, after compiled the model, that blocks didin't work. Is it possible to do that ? or Should I use different way to make it possible ?
2 Comments
Walter Roberson
on 23 Jul 2022
Edited: Walter Roberson
on 23 Jul 2022
Could you confirm that you want the same xpc host to send and receive the data?
If I understand correctly, xpc requires a dedicated program running on a real-time operating system, so if I understand correctly, you cannot have two different programs running on the same xpc exchanging data. As such you are setting up a loopback. Is that your intention?
Yavuzhan Erdem
on 25 Jul 2022
Edited: Yavuzhan Erdem
on 25 Jul 2022
Answers (1)
Dimitri MANKOV
on 25 Jul 2022
0 votes
Hi Yavuzhan,
You can achieve this by using the UDP Send and UDP Receive blocks from the Simulink Real-Time library (see here for examples in R2020a and earlier / here for R2020b and later). Please note that the UDP Send and UDP Receive blocks require the IP addresses of the corresponding Ethernet ports to be in different subnets.
If you're using MATLAB R2020b or later, these Ethernet ports should also be configured using the Speedgoat Ethernet Configuration tool before you deploy your model.
I hope this is helpful!
Dimitri
12 Comments
Yavuzhan Erdem
on 25 Jul 2022
Dimitri MANKOV
on 26 Jul 2022
Hi Yavuzhan,
I'm not sure to understand what you mean by "I would like to send data inside the same model"...
If you use UDP Send / Receive blocks, it implies that the signal will be physically transmitted via an Ethernet port. You could do a so-called loopback test, where you use one Ethernet Port of your target machine to send data out and another port to read it back in. But you have to use 2 different IP addresses in 2 different subnets for that. Also note that host-target communication is not restricted to the IP address 127.0.0.1
If you want your data to be logically transmitted from one part of your model to another without being translated into a physical signal, UDP Send / Receive blocks are not required.
Walter Roberson
on 26 Jul 2022
It is not clear to me why the source and destination would need to be in different subnets? It is very common to want to send UDP or TCP packets within the same subnet. When you require that they be in different subnets, then you are imposing the requirement that you must have a router and that you cannot do broadcasts (only multicast.) There would have to be a strong argument for requiring different subnets.
"Also note that host-target communication is not restricted to the IP address 127.0.0.1"
TCP defines 127.0.0.1 as being "same host". When you want to send between two processes on the same host, you would use normally use 127.0.0.1 instead of bothering to read out what the IP address of the interface is and copying that to the destination IP address.
When a packet is addressed to 127.0.0.1 then an implementation is permitted (but not obliged) to "short-circuit" the delivery, to keep the packet out of the hardware queues and just deliver it to the process registered as listening to the appropriate destination port and protocol. Not translating into a physical signal is a permitted optimization... but even if the optimization is not taken and the packet makes it to the hardware, the hardware is required to route the packet back to the same host.
Dimitri MANKOV
on 26 Jul 2022
Hi Walter,
My apologies about the mixup with the 127.0.0.1 IP address, I must have misread Yavuzhan's post above: I had the host-target communication in mind instead of a host-host communication. Thanks for catching that! Not sure if this optimization has been implemented in Simulink Real-Time, though...
As to IP addresses in separate subnets for each Ethernet port used by the model on the same target machine, this is a Simulink Real-Time limitation, see here.
Yavuzhan Erdem
on 29 Jul 2022
Walter Roberson
on 29 Jul 2022
Dimitri is saying that if you have two different Ethernet boards configured that they must be on different subnets.
We think using 127.0.0.1 might work, but it might not be optimized.
You just might have to resort to two different Ethernet boards on different subnets, with a router, and using non-127 addresses.
Dimitri MANKOV
on 29 Jul 2022
I agree with Walter. As an alternative, a direct connection between the two Ethernet boards would also be possible if you use broadcasting.
Yavuzhan Erdem
on 1 Aug 2022
Walter Roberson
on 1 Aug 2022
I do not know why 127.0.0.1 will not work . Also you could try filling in the actual ip address of the board, using the same ip for source and destination .
Yavuzhan Erdem
on 14 Aug 2022
Walter Roberson
on 15 Aug 2022
Sorry, I do not have anything resembling appropriate hardware to test this with, and I do not have access to the source code.
Yavuzhan Erdem
on 15 Aug 2022
Categories
Find more on Multicore Processor Targets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!