Real time Udp Send and Receive Block

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

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?
Yes. Absolutely ,I would like to do that . To clarify , for example, I can use "goto-from" blocks to move a signal from a subsystem to another subsystem inside the same model, but at this time I would like to send data by using the udp send and receive block inside the same model instead of the goto block or signal. So that my udp sender and receiver will be in the same model for transferring data. Shortly,I don't want to have two different programs running on the same xpc.Only, I want to run a model which has udp send and receiver to move data inside model, on the same xpc.
Is it clear now?

Sign in to comment.

Answers (1)

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

Hi Dimitri
Thanks for your attention and answer.
I also used the same blocks from the Simulink Real-Time Library. It works by transferring data from a host to a target device for communication. However, in my situation, I would like to send data inside the same model which runs on an xpc target. So I would like to use the same IP addresses for UDP send and receive blocks. I searched on the internet and found that '127.0.0.1' IP addresses are used to send data from host to host. When I run the model on a developer computer, which has windows operating system, it works. However, after building the model and obtaining a file with a .mldatx extension by using the rtwbuild command, it doesn't work on xpc target. So this is my problem.
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.
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.
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.
Hi Again,
As a result , Is it possible or not ? According to here , the real time udp send and receive blocks are used to transmit physically via an Ethernet port .
However, I would like to use like on windows. Because When I run the model with a packet is addressed to 127.0.0.1 on the windows , It is working. So as I understand, Windows also doesn't send physically.So Is it aplicable for xpc target ?. I am confused :)
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.
I agree with Walter. As an alternative, a direct connection between the two Ethernet boards would also be possible if you use broadcasting.
Hi Walter and Dimitri,
Thank you for your clarification about the answer. Last thing, I wonder that How can Windows run the model by using the same ethernet board on the computer without changing subnet or using router ? Do You have any idea about that ?
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 .
I also tried filling in the actual ip address of the board as same xpc ip address. However, It didin't work.
As I understood that there is no solution for this problem with actual capability of the xpc targets.
Sorry, I do not have anything resembling appropriate hardware to test this with, and I do not have access to the source code.
Thank you for your time and effort Walter!

Sign in to comment.

Categories

Asked:

on 23 Jul 2022

Commented:

on 15 Aug 2022

Community Treasure Hunt

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

Start Hunting!