フィルターのクリア

How can I get the sender's address and port values from the UDP receive S-function?

3 ビュー (過去 30 日間)
Erica Powers
Erica Powers 2023 年 6 月 26 日
コメント済み: Erica Powers 2023 年 7 月 18 日
I am using the slrealtime UDP receive block to get messages from 2 sources (for redundancy) and want to see from which source the message is coming from. Is there a way that we can modify the S-Function code to get the IP address and UDP port?
This is from the slrealtimeUDPReceive.cpp source code. Does the receive function on line 349 return those values via the remoteAddress and remotePort arguments?

回答 (1 件)

Shrey Tripathi
Shrey Tripathi 2023 年 6 月 27 日
Yes, you are correct. The receive function on line 349 returns the remote address and port information via the remoteAddress and remotePort arguments. You can declare variables to store the remote address and port to be able to access them to determine the source of the message. For example:
char remoteAddress[16]; // Assuming IPv4 address, change size if using IPv6
int remotePort;
...
while (dataAvailable && count > 0) {
...
if (numBytesRcvd > 0) {
// Process received data
// ...
// Print remote address and port
mexPrintf("Received message from %s:%d\n", remoteAddress, remotePort);
}
  1 件のコメント
Erica Powers
Erica Powers 2023 年 7 月 18 日
Thank you for your response!
I used this line in a new S-function and I want to compile it and eventually use it as a block in a model. However, the include files needed to build this are not in the Matlab source tree for this new S-function or the one I based it off of (slrealtimeUDPReceive.cpp). For example, in slrealtimeUDPReceive there's an include for SimulinkBlock/block_rtwcg.hpp that isn't in the Matlab files anywhere. How would you go about building it if the include files aren't there?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTarget Computer Setup についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by