9-21
9 Socket Service
NJ/NX-series CPU Unit Built-in EtherNet/IP Port User’s Manual (W506)
9-6 Details on Using the Socket Services
9
9-6-4 UDP Sample Programming
3 : // Request receiving data.
SktUDPRcv_instance(
Execute :=TRUE,
Socket :=WkSocket, // Socket
TimeOut :=UINT#0, // Timeout value
Size :=UINT#2000, // Receive data size
RcvDat :=RcvSocketDat[0]); // Receive data
IF (SktUDPRcv_instance.Done=TRUE) THEN
Stage :=INT#4; // Normal end
ELSIF (SktUDPRcv_instance.Error=TRUE) THEN
Stage :=INT#30; // Error end
END_IF;
4 : // Request closing data.
SktClose_instance(
Execute :=TRUE,
Socket :=WkSocket); // Socket
IF (SktClose_instance.Done=TRUE) THEN
Stage :=INT#0; // Normal end
ELSIF (SktClose_instance.Error=TRUE) THEN
Stage :=INT#40; // Error end
END_IF;
0 : // Normal end
DoSendAndRcv:=FALSE;
Trigger :=FALSE;
ELSE // Interrupted by error.
DoSendAndRcv:=FALSE;
Trigger :=FALSE;
END_CASE;
END_IF;
Remote Node Programming
In this example, programming is also required in the remote node. The order of sending and receiv-
ing is reversed in comparison with the above procedure.
1
The SktUDPCreate instruction is used to request creating a UDP socket.
2
The SktUDPRcv instruction is executed to request reception. The receive data is stored in
RcvSocketDat[].
3
Execute the SktUDPSend instruction to request sending. The data in SendSocketDat[] is sent.
4
The SktClose instruction is executed to close the socket.