9-27
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-5 TCP Sample Programming
0 : // Normal end
DoTCP :=FALSE;
Trigger :=FALSE;
ELSE // Interrupted by error.
DoTCP :=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 SktTCPAccept instruction is executed to request accepting a TCP socket.
2
The SktTCPRcv instruction is executed to request receiving data. The receive data is stored in
RcvSocketDat[].
3
The SktTCPSend instruction is executed to request sending data. The data in SendSocketDat[]
is sent.
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).
Internal
Variables
Variable Data type Initial value Comment
Trigger BOOL False Execution condi-
tion
DoTCP 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
SktTCPAccept_instance SktTCPAccept
SktTCPSend_instance SktTCPSend
SktTCPRcv_instance SktTCPRcv
SktClose_instance SktClose
External
Variables
Variable Data type Constant Comment
_EIP_EtnOnlineSta
*1
BOOL Online