Socket Service W516-E1-01+CP1L-Ex
Socket Service W516-E1-01+CP1L-Ex
0.00 A202.07
CMND
S D00100
D D00200
C D00300
15 87 0
S: D00100 0 5 0 1 Command code: 0501 hex(Controller Inforamtion Read)
15 87 0
D: D00300 0 0 0 2 Bytes of command data: 0002 hexadecimal (2 decimal)
C+2: D00302 0 0 0 0 Transmit to the local network and the device itself
Ethernet
TCP/UDP
protocol SYSMAC
CP1L
CP1L-EL/EM POWER
RUN
NC
COM
00
01
02
03
04
05
06
07
08
09
10
11
00
01
02
03
04
05
06
07
08
09
10
11
CPU Unit
ERR/ALM
INH
LNK/ACT
BKUP
1 2
00 01 02 03 04 06 00 01 03 04 06
ANALOG INPUT COM(V+) COM 05 07 COM 02 COM 05 07
MAC Address:
01234567890A
UDP TCP
Socket
TCP/UDP Parameters
protocol
188
Socket Services Section 6-6
㪊㪅㩷Select Transfer to PLC from the Options Menu, and then click the Yes
button. The Setup data in the allocated DM Area will be transferred to the
CPU Unit.㩷
Precautions A Socket Service Parameter Area cannot be used for other sockets once
open processing has been successfully completed for it. Check the socket
status before attempting to open a socket. TCP socket status is provided in
words m+4 to m+6 in the DM Area for sockets 1 to 3.
Note When a send or receive request is made, the data will be automatically sent or
received according to the send/receive data address in the Socket Service
Parameter Area. When processing has been completed, a response code will
be automatically stored in the Socket Service Parameters.
189
Socket Services Section 6-6
Check TCP Connection/UDP Open Flag. OFF? The specified UDP socket is
NO already open.
Is Bit 15 (Open Flag) in the socket status word for YES
the socket being used OFF?
(Checks to see if the socket is open before com-
munications and close processing.)
Note For details about timing charts, refer to SECTION 6 Socket Services in the
Ethernet Units Construction of Applications Operation Manual (Cat. No.
W421-E1).
Socket services cannot support CMND command.
190
Socket Services Section 6-6
Note Make settings using the PLC settings function in the CX-Programmer (to be
included in version 9.4 and higher).
191
Socket Services Section 6-6
192
Socket Services Section 6-6
Socket Service
Bit
15 8 7 0
A567 TCP/UDP Socket No. 1 Status
A568 TCP/UDP Socket No. 2 Status
A569 TCP/UDP Socket No. 3 Status
A570 Reserved
A571 Socket Service Request Switches 2 Socket Service Request Switches 1
A572 Reserved Socket Service Request Switches 3
Closing Flag
193
Socket Services Section 6-6
Note Do not forcibly manipulate the above status flags during socket service is
used.
Socket Service Request
Switches 1 to 3 15 14 13 12 11 10 9 8
7 6 5 4 3 2 1 0
A571 to A572
UDP Open Request Switch
TCP Passive Open Request Switch
TCP Active Open Request Switch
Send Request Switch
Receive Request Switch
Close Request Switch
194
Socket Services Section 6-6
195
Socket Services Section 6-6
Offset Word
Bit
15 08 07 00
m D32400 TCP Socket No. 1 Number of Bytes Received
m+1 D32401 TCP Socket No. 2 Number of Bytes Received
For each TCP socket, the number of bytes of data in the reception buffer is
stored in one word. A maximum of 4,096 bytes of data can be held in the
reception buffer, but a value of only up to the maximum value (1,024 bytes)
that can be set for receive requests by manipulating control bits is stored.
0000 hex: 0 bytes
0400 hex: 1,024 bytes
The Data Received Flag in the CIO Area turns ON and OFF linked to this
word. This area is given a value of 0000 hex when a receive request is exe-
cuted by manipulating control bits. If any data remains in the reception buffer
after the receive request processing is completed, the remaining number of
bytes is stored and the Data Received Flag turns ON again.
Before a receive request is executed, a check is performed to confirm that the
required data is available.
TCP Socket No. (1 to 3): Connection Status
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
m+4 to m+6
The connection status for each TCP socket is stored by code in this word. For
details, refer to Appendix H TCP Status Transitions.
196
Socket Services Section 6-6
When socket services are requested by control bit manipulation, the settings
must be made in advance in a Socket Service Parameter Area. The parame-
ters used will vary depending on the service requested.
Parameter Settings
The following table shows the parameters that are required for each service
and the use of the parameters by the socket service.
UDP Socket Services
Parameter No. of Range Socket service
words (decimal values in UDP UDP UDP UDP
parentheses) open receive send close
Socket option 1 Specified bit --- --- --- ---
UDP/TCP socket No. 0001 to 0003 hexadecimal W W W W
(1 to 3)
Local UDP/TCP port No. 1 0000 to FFFF hexadecimal W --- --- ---
(0 to 65,535)
Remote IP address 2 00000000 to FFFFFFFF --- R W ---
hexadecimal
(0.0.0.0 to 255.255.255.255)
Remote UDP/TCP port No. 1 0000 to FFFF hexadecimal --- R W ---
(0 to 65,535)
Number of bytes to send/ 1 0000 to 07C0 hexadecimal --- RW RW ---
receive (0 to 1,024 bytes)
Send/Receive data address 2 Memory area address --- W W ---
Time out time 1 0000 to FFFF hexadecimal --- W --- ---
(Unit: 100 ms) (0 to 65,535)
(0: No limit, 0.1 to 6,553.5 s)
Response code 1 --- R R R R
197
Socket Services Section 6-6
Parameters
Socket Option For the TCP OPEN REQUEST (ACTIVE or PASSIVE) command, specifies
whether or not the keep-alive function is to be used. When the keep-alive
function is used, bit 8 is ON.
UDP/TCP Socket No. Specify the number of the UDP or TCP socket to open.
Local UDP/TCP Port No. Specify the number of the UDP or TCP port for the socket to use for communi-
cations.
• Do not specify the port being used as the FINS UDP port (default: 9600)
in an open request for a UDP socket.
• Do not specify the port being used as the FINS TCP port (default: 9600)
in an open request for a TCP (active or passive) socket.
• Do not specify auto connection UDP port number 9600 in an open
request for a UDP socket.
• Do not specify auto connection TCP port number 9600 in an open request
for a TCP (active or passive) socket.
• As a rule, use port numbers 1,024 and higher.
If port number 0 is specified when for an active TCP open, the TCP port num-
ber will be automatically allocated and the number of the port that was
opened will be stored in the local UDP/TCP port number in the Socket Service
Parameter Area (i.e., the actual port number will be overwritten on the value of
0 set by the user).
198
Socket Services Section 6-6
199
Socket Services Section 6-6
Number of Bytes to Send/ Send the number of bytes to be sent or the number of bytes to receive. When
Receive the transfer has been completed, the actual number of bytes that have been
sent or received will be written here.
Send/Receive Data Specify the address of the first word to send or the address of the first word
Address where data is to be received. Always set the bit number to 00 hexadecimal.
Offset 15 8 7 0
+6 Area Leftmost 2 digits
designation of word address
Rightmost 2 digits Bit number
+7
of word address (always 00 Hex)
Response Codes When processing of a request has been completed for socket services exe-
cuted using Socket Service Request Switches, a response code will be stored
in the Response Code word in the Socket Service Parameter Area. The fol-
lowing response codes will be stored depending on the service that was
requested.
UDP Socket Open Request
Response Meaning
code
0000 Normal end
0105 Local IP address setting error.
1100 UDP socket number is not 1 to 8 or local UDP port number is 0.
110C Request Switch turned ON during other processing.
220F Specified socket is already open.
2211 Unit is busy; cannot execute.
2606 Specified socket is already open as TCP socket; cannot open
UDPsocket.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.
0049 The same UDP port number has been specified more than once
(EADDRINUSE).
0081 The specified socket was closed during open processing.
200
Socket Services Section 6-6
201
Socket Services Section 6-6
Note These response codes will be returned only on large, multilevel networks.
TCP Socket Active Open Request
Response Meaning
code
0000 Normal end
0105 Local IP address setting error.
1100 TCP socket number is not 1 to 8 or local TCP port number is 0.
110C Request Switch turned ON during other processing.
220F Specified socket is already open or already processing an openre-
quest.
2211 Unit is busy; cannot execute.
2606 Specified socket is already open as UDP socket; cannot open
TCPsocket.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.
000D Remote IP address parameter error (EACCES).
0045 Error in communications with remote node (ECONNABORTED).
0049 The same port number has been specified more than once (EAD-
DRINUSE).
004B (See note.) Error in communications with remote node (ECONNRESET).
004C Remote IP address parameter error (EADDRNOTAVAIL).Wrong
parameter designation.An attempt was made to set the local TCP
port of the local node toActive Open.
0053 Communications error with remote node (ETIMEDOUT).No
remote node.
0081 The specified socket was closed during open processing.
Note These response codes will be returned only on large, multilevel networks.
202
Socket Services Section 6-6
Note These response codes will be returned only on large, multilevel networks.
TCP Socket Send Request
Response Meaning
code
0000 Normal end
0302 CPU Unit error; cannot execute.
1100 Number of bytes to send not in allowable range.
1101 The area designation of the Send/Receive Data Address is not
inallowable range.
1103 The bit number in the Send/Receive Data Address is not 00.
110C Request Switch turned ON during other processing.
220F Specified socket is already processing a send request.
2210 The specified socket is not been connected.
2211 Unit is busy; cannot execute.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.
0020 Connection with remote socket broken during send (EPIPE).
003E Internal buffer cannot be obtained due to high reception traf-
fic(ENOBUFS).
0045 (See note.) Error in communications with remote node (ECONNABORTED).
004A Error in communications with remote node (ECONNREFUSED).
004E (See note.) Remote IP address parameter error (ENETUNREACH).
0053 (See note.) Error in communications with remote node (ETIMEDOUT).
0081 The specified socket was closed during send processing.
203
Socket Services Section 6-6
Note These response codes will be returned only on large, multilevel networks.
Note For details, refer to SECTION 6 Socket Services in the Ethernet Units Con-
struction of Applications Operation Manual (Cat. No. W421-E1).
Data Flow The data will flow between the CPU Unit, Ethernet Unit, and host computer as
shown in the following diagram.
Line Ethernet CPU Unit
Host computer (Ethernet) Unit
Request Switches and ex-
Sent to line. ecution bits turned ON
(see note).
Note Here, “execution bits” refer to W0.00 to W0.03, which are used in the ladder
diagram to control execution of communications.
Basic Operations • W0.00 is turned ON to request opening a TCP socket from the Ethernet Unit.
• W0.01 is turned ON to request closing the TCP socket from the Ethernet Unit.
• W0.02 is turned ON to request sending data from the Ethernet Unit. Data
(100 bytes) is sent beginning at D00000.
• W0.03 is turned ON to request receiving data from the Ethernet Unit. The
data that is received (100 bytes) is stored beginning at D01000.
• One of the bits between W1.00 and W1.03 will turn ON if an error occurs.
Refer to 6-7-5 Socket Service Request Switches for information on errors.
204
Socket Services Section 6-6
Program Memory Map The send and receive data and bits (flags) used by the program are shown in
the following diagram.
DM Area
15 00
DM00000
DM00049
15 00
DM01000
DM01049
WR Area
15 03 02 01 00
TCP
W0 Receive TCP TCP TCP
Bit Send Bit Close Bit Open Bit
205
Socket Services Section 6-6
Programming Example
W0.00
TCP Passive Open
@RSET When the TCP Open Bit (W0.00) turns ON, the TCP
W1.00 Open Error Flag (W1.00) is turned OFF and the TCP
@SET Opening Flag (W2.00) is turned ON to initialize
W2.00 processing.
W0.00 W2.00
MOV(021)
#1 When the TCP Opening Flag (W2.00) turns ON, the
D32408
following parameters are written to the parameter
MOV(021) area for socket number 1.
#1000 D32408: 0001 Hex = UDP/TCP socket No. 1
D32409 D32409: 1000 Hex = Local UDP/TCP port No. 4096
D32410 and D32411:
MOV(021)
C0A8 FA05 Hex =
#C0A8
D32410
Remote IP address 192.168.250.5
D32412: 0000 Hex = Any remote UDP/TCP port No.
MOV(021) D32416: 0000 Hex = No timeout time
#FA05
D32411
MOV(021)
#0
D32412
MOV(021)
#0
W0.00 W2.00 D32416
After the parameters have been set, the TCP Passive
SET
A571.01 Open Request Switch (A571.01) is turned ON and the
TCP Opening Flag (W2.00) is turned OFF.
RSET
W2.00
If the TCP Passive Open Request Switch (A571.01)
turns OFF while the TCP Opening Flag (W2.00) is OFF,
W0.00 W2.00 A571.01 the contents of the response code (D32417) in the
<>(305) SET Socket Service Parameter Area is checked, and if it is
D32417 W1.00 not 0000 Hex (normal end), the TCP Open Error Flag
#0 (W1.00) is turned ON.
W0.00 W2.00 A571.01 After the execution results have been checked, the
RSET TCP Open Bit (W0.00) is turned OFF.
W0.00
W0.01
TCP Close
@RSET When the TCP Close Bit (W0.01) turns ON, the TCP
W1.01 Close Error Flag (W1.01) is turned OFF and the TCP
@SET Closing Flag (W2.01) is turned ON to initialize
W2.01 processing.
W0.01 W2.01
MOV(021)
#1
W0.01 W2.01 D32408 When the TCP Closing Flag (W2.01) turns ON, the
SET following parameter is written to the parameter area for
A571.05 socket number 1.
D32408: 0001 Hex = UDP/TCP socket No. 1
RSET
W2.01
After the parameter has been set, the Close Request
W0.01 W2.01 A571.05
Switch (A571.05) is turned ON and the TCP Closing
<>(305) SET Flag (W2.01) is turned OFF.
D32417 W1.01
#0 If the Close Request Switch (A571.05) turns OFF
while the TCP Opening Flag (W2.01) is OFF, the
W0.01 W2.01 A571.05
contents of the response code (D32417) in the
RSET Socket Service Parameter Area is checked, and if it
W0.01 is not 0000 Hex (normal end), the TCP Close Error
Flag (W1.01) is turned ON.
Continued on next page. After the execution results have been checked, the
TCP Close Bit (W0.01) is turned OFF.
206
Socket Services Section 6-6
MOV(021)
#0
W0.02 W2.02 D32415
SET
After the parameters have been set, the Send Request Switch
A571.03 (A571.03) is turned ON and the TCP Sending Flag (W2.02) is
turned OFF.
RSET
W2.02
=(300) @SET
D32400 W2.03
&100
W0.03 W2.03 TCP Receive
MOV(021) When the TCP Receive Bit (W0.03) turns ON, the TCP Receive
#1 Error Flag (W1.03) is turned OFF and the TCP Data
D32408
Received/Requested Flag (A567.13), and the Number of Bytes
MOV(021) Received at TCP Socket (D33400) are checked. If the data is stored
#64 in the buffer, the TCP Receiving Flag (W2.03) turns ON.When the
D32413
TCP Receiving Flag (W2.03) turns ON, the following parameters
MOV(021) are written to the parameter area for socket number 1.
#8200 D32408: 0001 Hex = UDP/TCP socket No. 1
D32414 D32413: 0064 Hex = No. of send/receive bytes is 100
MOV(021) D32414 and D32415:
#0 8203 E800 Hex =
D32415 Send/receive data address D01000
MOV(021) D32416: 0000 Hex = No timeout time.
#0
W0.03 W2.03 D32416
SET
A571.04
RSET
W2.03
W0.03 W2.03 A571.04 If the Receive Request Switch (A571.04) turns OFF while the TCP
Receiving Flag (W2.03) is OFF, the contents of the response code
RSET
W0.03 (D32417) in the Socket Service Parameter Area is checked, and if it
is not 0000 Hex (normal end), the TCP Receive Error Flag (W1.03)
is turned ON.
After the execution results have been checked, the TCP Receive Bit
(W0.03) is turned OFF.
Note When using the above programming example, change the bit and word
addresses as necessary to avoid using the same areas used by other parts of
the user program or the CPU Bus Unit.
207