9-19
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
In this sample, the UDP socket service is used for data communications between the NJ/NX-series
Controller and a remote node.
The processing procedure is as follows:
1
The SktUDPCreate instruction is executed to request creation of a UDP socket.
2
Execute the SktUDPSend instruction to request sending. The data in SendSocketDat[] is sent.
3
The SktUDPRcv instruction is executed to request reception. The receive data is stored in
RcvSocketDat[].
4
The SktClose instruction is executed to close the socket.
ST
*1 For an NX701 CPU Unit, replace the variable with _EIP1_EtnOnlineSta (Port1 Online) or _EIP2_EtnOnlineSta
(Port2 Online), depending on the built-in EtherNet/IP port which is used.
For an NX1P2 CPU Unit, replace the variable with _EIP1_EtnOnlineSta (Port1 Online).
9-6-4 UDP Sample Programming
Internal
Variables
Variable Data type Initial value Comment
Trigger BOOL False Execution condi-
tion
DoSendAndRcv BOOL False Processing
Stage INT 0 Status change
RcvSocketDat ARRAY[0..1999] OF
BYTE
[2000(16#0)] Receive data
WkSocket _sSOCKET (Handle:=0,
SrcAdr:=(PortNo:=0, IpAdr:=’’),
DstAdr:=(PortNo:=0, IpAdr:=’’))
Socket
SendSocketDat ARRAY[0..1999] OF
BYTE
[2000(16#0)] Send data
SktUDPCreate_instance SktUDPCreate
SktUDPSend_instance SktUDPSend
SktUDPRcv_instance SktUDPRcv
SktClose_instance SktClose
External
Variables
Variable Data type Constant Comment
_EIP_EtnOnlineSta
*1
BOOL Online
IP address: 192.168.250.1
UDP port number: 6000
Ethernet line
Built-in EtherNet/IP Port
Data received.
Remote node
IP address: 192.168.250.2
UDP port number: 6001
Data sent.