9 Socket Service
9-24
NJ/NX-series CPU Unit Built-in EtherNet/IP Port User’s Manual (W506)
In this sample, the TCP 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 SktTCPConnect instruction is executed to request connecting to the TCP port on the
remote node.
2
The SktClearBuf instruction is executed to clear the receive buffer for a TCP socket.
3
The SktGetTCPStatus instruction is executed to read the status of a TCP socket.
4
The SktTCPSend instruction is executed to request sending data. The data in SendSocketDat[]
is sent.
5
The SktTCPRcv instruction is executed to request receiving data. The receive data is stored in
RcvSocketDat[].
6
The SktClose instruction is executed to close the socket.
ST
9-6-5 TCP Sample Programming
Internal
Variables
Variable Data type Initial value Comment
Trigger BOOL False Execution condition
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
SktTCPConnect_
instance
SktTCPConnect
SktClearBuf_instance SktClearBuf
SktGetTCPStatus_
instance
SktGetTCPStatus
SktTCPSend_instance SktTCPSend
SktTCPRcv_instance SktTCPRcv
SktClose_instance SktClose
External
Variables
Variable Data type Constant Comment
_EIP_EtnOnlineSta
*1
BOOL Online
IP address: 192.168.250.1
TCP port number: Automatically assigned.
Ethernet line
Built-in EtherNet/IP Port
Data received.
Remote node
IP address: 192.168.250.2
TCP port number: 6000
Data sent.