CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Mon Nov 18, 2019 9:58 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Udp and multicast
PostPosted: Tue Mar 21, 2017 5:46 pm 
Offline

Joined: Fri Oct 25, 2013 9:24 am
Posts: 4
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:
Code:
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;
Code:
UdpPeer(
   xEnable   := TRUE,
   ipAddr   := IP_Multicast,
   uiPort   := IP_Port   );

UdpPeer returns "NO_ERROR" but UdpSend returns "UDP_SEND_ERROR"

Instead, by using:
Code:
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


Top
   
 Post subject: Re: Udp and multicast
PostPosted: Wed Mar 22, 2017 6:20 pm 
Offline

Joined: Fri Oct 25, 2013 9:24 am
Posts: 4
I solved (partially?) the issue by differentiating the ip address and port of Peer and sender.

Code:
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);
IF UdpPeer.xError THEN
   UdpPeer(xEnable := FALSE);
   Send         := FALSE;
END_IF

RTR_Send(CLK:=OneShotCmd); (* check rise of send command *)
IF RTR_Send.Q AND UdpPeer.xActive AND NOT UdpPeer.xError THEN
   Send   := TRUE;
END_IF
   
(* UPD sender *)
UdpSend(
   xExecute   := Send,
   ipAddr   := SenderIpAddr,
   uiPort   := SenderIpPort,
   hPeer   := UdpPeer.hPeer,
   szSize   := SIZEOF(DataTx),
   pData   := ADR(DataTx),
   udiTimeOut   := 1000000, (* usec *)
);
   
IF UdpSend.xDone THEN
   Send   := FALSE;   
END_IF
IF UdpSend.xError THEN
   Send   := FALSE;
   UdpSend(xExecute:=FALSE);   
END_IF
   


Problem: it is the right way ? Is there any guidelines for using these libraries ?


Top
   
 Post subject: Re: Udp and multicast
PostPosted: Fri Mar 31, 2017 2:22 pm 
Offline

Joined: Fri Oct 25, 2013 9:24 am
Posts: 4
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.


Top
   
 Post subject: Re: Udp and multicast
PostPosted: Fri Mar 31, 2017 2:24 pm 
Offline

Joined: Fri Oct 25, 2013 9:24 am
Posts: 4
The question is now:
how can i read the UDP multicast/broadcast data sent from other devices ?

Is it possible in codesysV3 ?


Top
   
 Post subject: Re: Udp and multicast
PostPosted: Tue Jan 16, 2018 8:06 am 
Offline
Frequent User
Frequent User

Joined: Thu Mar 17, 2016 1:24 pm
Posts: 190
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.

_________________
Make CODESYS great again


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited