Hi, Good afternoon can anybody help me with UDP Multicast code.
I am not able to send or recieve data when code is dumped on linux device.
Below is my code.
Declaration:
PROGRAM udp_multicast
VAR
oneTimeFlag :UINT :=0;
state: INT:=0;
driver: UDP.UDPDriver;
//port : UDP.Port;//moved to GVL
src_ipAddr_ud: UDINT;
src_ipAddr_st:STRING := '192.168.127.155';//'192.168.1.155';//ipms ip address
dst_ipAddr_ud:UDINT;
group_ipAddr_st:STRING := '239.1.5.10';
//group_ipAddr_ud:UDINT;
result: SysTypes.RTS_IEC_RESULT; //result of recieve function.
bind: UDINT; //result of binding.
resultCreate:SysTypes.RTS_IEC_RESULT;//result of port creation.
timer:BLINK;
temFlag :INT:= 0;
post:INT :=0;
checksumFunc:checksumXor;
localStringBuf:STRING[500];
chksum:BYTE;
dataBuffer:POINTER TO BYTE;
checksumString:ARRAY[0..5] OF BYTE;
recvSize:__XINT;
errorCode:UDINT;
joinGroupErrorCode:UDINT;
END_VAR ************8
Implementation:
IF oneTimeFlag <> 1 THEN
oneTimeFlag:=1;
resultCreate := driver.CreatePort(ADR(GVL.port));
src_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIPAddress:= src_ipAddr_st);
GVL.group_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIpAddress:= group_ipAddr_st);
GVL.port.IPAddress := src_ipAddr_ud;
GVl.port.ReceivePort:= GVL.src_port;//port on which messages are expected.
GVl.port.SendPort := GVL.dest_port;
GVl.port.OperatingSystem := 0; //0- any system
GVL.port.Socket :=3; //3- socket type is multicast
bind := GVL.port.Bind(udiIPAddress:=src_ipAddr_ud,);
GVl.port.JoinGroup(udiGroupAddress:= GVL.group_ipAddr_ud,udiInterfaceAddress:= src_ipAddr_ud,eLogCode=>joinGroupErrorCode);
Hi, Good afternoon can anybody help me with UDP Multicast code.
I am not able to send or recieve data when code is dumped on linux device.
Below is my code.
Declaration:
PROGRAM udp_multicast
VAR
oneTimeFlag :UINT :=0;
state: INT:=0;
driver: UDP.UDPDriver;
//port : UDP.Port;//moved to GVL
src_ipAddr_ud: UDINT;
src_ipAddr_st:STRING := '192.168.127.155';//'192.168.1.155';//ipms ip address
dst_ipAddr_ud:UDINT;
group_ipAddr_st:STRING := '239.1.5.10';
//group_ipAddr_ud:UDINT;
result: SysTypes.RTS_IEC_RESULT; //result of recieve function.
bind: UDINT; //result of binding.
resultCreate:SysTypes.RTS_IEC_RESULT;//result of port creation.
timer:BLINK;
temFlag :INT:= 0;
post:INT :=0;
checksumFunc:checksumXor;
localStringBuf:STRING[500];
chksum:BYTE;
dataBuffer:POINTER TO BYTE;
checksumString:ARRAY[0..5] OF BYTE;
recvSize:__XINT;
errorCode:UDINT;
joinGroupErrorCode:UDINT;
END_VAR
************8
Implementation:
IF oneTimeFlag <> 1 THEN
oneTimeFlag:=1;
resultCreate := driver.CreatePort(ADR(GVL.port));
src_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIPAddress:= src_ipAddr_st);
GVL.group_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIpAddress:= group_ipAddr_st);
GVL.port.IPAddress := src_ipAddr_ud;
GVl.port.ReceivePort:= GVL.src_port;//port on which messages are expected.
GVl.port.SendPort := GVL.dest_port;
GVl.port.OperatingSystem := 0; //0- any system
GVL.port.Socket :=3; //3- socket type is multicast
bind := GVL.port.Bind(udiIPAddress:=src_ipAddr_ud,);
GVl.port.JoinGroup(udiGroupAddress:= GVL.group_ipAddr_ud,udiInterfaceAddress:= src_ipAddr_ud,eLogCode=>joinGroupErrorCode);
END_IF
timer(ENABLE:=TRUE,TIMELOW:=T#100MS,TIMEHIGH:=T#100MS);
IF timer.OUT = TRUE THEN
GVL.port.Send(udiIPTo:=GVL.group_ipAddr_ud,GVL.dest_port,pbyData:=ADR(GVL.writeData),diDataSize:=SIZEOF(GVL.writeData));
ELSE
SysMemSet(ADR(GVL.readData[0]),0,SIZEOF(GVL.readData));
result := GVl.port.Receive(ADR(GVL.readData),diDataSize:=SIZEOF(GVL.readData),udiIPFrom=>dst_ipAddr_ud,diRecvSize=>recvSize,eLogCode=>errorCode);
SysMemMove(ADR(GVL.readDataBuf[0]),ADR(GVL.readData[0]),SIZEOF(GVL.readData));
END_IF
post:=LEN(GVL.readDataBuf);
did you check this example: https://forge.codesys.com/prj/codesys-example/nbs/home/Home/