Hi all,
I'm trying to send data by UDP sockets but I get always error with multicast IP addresses (i.e. 239.2.3.4).
I'm able to send data to a "normal" IP address like 192.168.10.25 but not multicast or broadcast. I don't know what I wrong. I am new in Codesys v3.
declarations:
IP_Addr:Â Â NBS.IP_ADDR:=(sAddr:='192.168.10.25');IP_Multicast:Â Â NBS.IP_ADDR:=(sAddr:='239.2.3.4');IP_Port:Â Â Â Â UINT:=2053;UdpPeer:Â Â Â Â nbs.UDP_Peer;UdpSend:Â Â Â Â nbs.UDP_Send;
by using;
UdpPeer(  xEnable  :=TRUE,  ipAddr  :=IP_Multicast,  uiPort  :=IP_Port  );
UdpPeer returns "NO_ERROR" but UdpSend returns "UDP_SEND_ERROR"
Instead, by using:
UdpPeer(  xEnable  :=TRUE,  (*ipAddr  :=IP_Addr,*)    ipMultiCast  :=IP_Multicast,  uiPort  :=IP_Port  );
UdpPeer status returns "WRONG_PARAMETER" .
Same results by setting or ipAddr = '255.255.255.255' or '0.0.0.0' (see library doc)
Has someone an idea ?
Many thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I solved (partially?) the issue by differentiating the ip address and port of Peer and sender.
PeerIpAddr.sAddr  :='255.255.255.255'; (* or 127.0.0.1 or other non multicast IP address *)PeerIpPort      :=49999; (* or other port not used *)SenderIpAddr.sAddr :='239.2.3.4';SenderIpPort    :=2053;RTR:  R_Trig;Send:   BOOL;DataTx:  STRING:='Hello Multicast !!';--------------------------------------------------------------------------UdpPeer(xEnable :=TRUE, ipAddr :=PeerIpAddr, uiPort :=PeerIpPort);IFUdpPeer.xErrorTHEN
  UdpPeer(xEnable :=FALSE);
  Send      :=FALSE;END_IFRTR_Send(CLK:=OneShotCmd); (* check rise of send command *)IFRTR_Send.QANDUdpPeer.xActiveANDNOTUdpPeer.xErrorTHEN
  Send  :=TRUE;END_IF
 Â
(*UPDsender*)UdpSend(
  xExecute  :=Send,
  ipAddr  :=SenderIpAddr,
  uiPort  :=SenderIpPort,
  hPeer  :=UdpPeer.hPeer,
  szSize  :=SIZEOF(DataTx),
  pData  :=ADR(DataTx),
  udiTimeOut  :=1000000, (*usec*));
 Â
IFUdpSend.xDoneTHEN
  Send  :=FALSE;  END_IFIFUdpSend.xErrorTHEN
  Send  :=FALSE;
  UdpSend(xExecute:=FALSE);  END_IF
 Â
Problem: it is the right way ? Is there any guidelines for using these libraries ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK I've fixex the data transmission. You Don't need to separate IPaddr. and IPport of Peer and Sender. You only need to setup in the right way the Gateway of the device.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I'm trying to send data by UDP sockets but I get always error with multicast IP addresses (i.e. 239.2.3.4).
I'm able to send data to a "normal" IP address like 192.168.10.25 but not multicast or broadcast. I don't know what I wrong. I am new in Codesys v3.
declarations:
by using;
UdpPeer returns "NO_ERROR" but UdpSend returns "UDP_SEND_ERROR"
Instead, by using:
UdpPeer status returns "WRONG_PARAMETER" .
Same results by setting or ipAddr = '255.255.255.255' or '0.0.0.0' (see library doc)
Has someone an idea ?
Many thanks in advance
I solved (partially?) the issue by differentiating the ip address and port of Peer and sender.
Problem: it is the right way ? Is there any guidelines for using these libraries ?
OK I've fixex the data transmission. You Don't need to separate IPaddr. and IPport of Peer and Sender. You only need to setup in the right way the Gateway of the device.
The question is now:
how can i read the UDP multicast/broadcast data sent from other devices ?
Is it possible in codesysV3 ?
Dear Edwin, can you help with simple example UDP Multicast? (Sender/Receiver)
Another topic with similar situation:
https://forum-de.codesys.com/viewtopic. ... 324#p17085
It would be nice to get simple example (for example, for Raspberry Pi) to undestand how it works in CDS V3.