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
Walter Roberson
2022년 7월 23일
편집: Walter Roberson
2022년 7월 23일
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
2022년 7월 25일
편집: Yavuzhan Erdem
2022년 7월 25일
답변 (1개)
Dimitri MANKOV
2022년 7월 25일
0 개 추천
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
Yavuzhan Erdem
2022년 7월 25일
Dimitri MANKOV
2022년 7월 26일
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
2022년 7월 26일
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
2022년 7월 26일
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
2022년 7월 29일
Walter Roberson
2022년 7월 29일
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
2022년 7월 29일
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
2022년 8월 1일
Walter Roberson
2022년 8월 1일
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
2022년 8월 14일
Walter Roberson
2022년 8월 15일
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
2022년 8월 15일
카테고리
도움말 센터 및 File Exchange에서 System Configuration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!