0% found this document useful (0 votes)
104 views20 pages

Socket Service W516-E1-01+CP1L-Ex

The socket services allow devices on an Ethernet network to send and receive data using UDP or TCP protocols. To use socket services, parameters must be set in a dedicated DM area and control bits turned on in the AR area to request services. When a service completes, the control bit is turned off. Data is automatically handled to/from specified I/O memory locations. Up to three ports can be used for UDP and TCP socket services simultaneously.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views20 pages

Socket Service W516-E1-01+CP1L-Ex

The socket services allow devices on an Ethernet network to send and receive data using UDP or TCP protocols. To use socket services, parameters must be set in a dedicated DM area and control bits turned on in the AR area to request services. When a service completes, the control bit is turned off. Data is automatically handled to/from specified I/O memory locations. Up to three ports can be used for UDP and TCP socket services simultaneously.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Socket Services Section 6-6

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+1: D00301 0 0 3 E Bytes of response data: 003E hexadecimal (62 decimal)

C+2: D00302 0 0 0 0 Transmit to the local network and the device itself

C+3: D00303 0 3 F A Node number 3, unit address FA (Built-in Ethernet Port)

C+4: D00304 0 7 0 3 Response requested, port number 7, 3 retries

C+5: D00305 0 0 6 4 Response monitoring time: 0064 hexadecimal (10 seconds)

6-6 Socket Services


The socket services allow devices on the Ethernet to send and receive vari-
ous data using either the UDP or TCP protocol.

6-6-1 Overview of Socket Service


Manipulating Dedicated The way to use socket services is to set the required parameters in the
Control Bits parameter area allocated in the DM Area, and then to request particular UDP
or TCP socket services by turning ON dedicated control bits in the AR Area.
When the PLC has completed the requested process, the same bit is turned
OFF to provide notification. Data that is sent or received is automatically han-
dled according to the I/O memory locations specified in the parameter area.
A total of three ports (UDP and TCP combined) can be used for socket ser-
vices.
UNIX computer, etc.
(node with socket
services interface)

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

V1+ V2+ COM

MAC Address:
01234567890A
UDP TCP
Socket

Service request switch


IP

TCP/UDP Parameters
protocol

188
Socket Services Section 6-6

6-6-2 Procedure for Using Socket Service Functions


Procedure for Using Socket Service Functions

1. Make the basic settings.


Refer to 6-4-3 Basic Settings.㩷

2. Use the CX-Programmer or Programming Console to make the socket


service settings in the socket service parameter areas 1 to 3 (m+8 to m+37)
allocated in the DM Area.
Note The first word m in the allocated DM Area = D32400㩷

㪊㪅㩷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

6-6-3 Socket Services and Socket Status


When using socket services, it is important to consider the timing of the status
changes in the Socket Status Area. The diagram below shows a flowchart for
opening UDP. The flow is similar for other socket services. Replace the names
of the appropriate flags in the flowchart to adapt it to other socket services.

Start UDP Open.

Program Flow Error Evaluation

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.)

Turn ON UDP Open Request Switch.

This Socket Service Request Switch is used to request


opening of a UDP socket to the Ethernet Unit.

Confirm end of processing. ON/OFF?

This Socket Service Request Switch that was turned OFF


ON will be turned OFF by the Ethernet Unit when
processing has been completed.

An error occurred. The specified


Check response code. 0000? socket could not be opened.
NO
Is the response code 0000, indicating a normal end? YES

UDP socket opened.

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

6-6-4 PLC Setup for Socket Services


Socket Services
CX-Programmer tab Setting
Built-in Ethernet Keep-alive

Item Contents Default


TCP/IP keep-alive Set the liveness-checking interval. When socket services using either 0
FINS/TCP or TCP/IP are used, the connection will be terminated if there is (120 minutes)
no response from the remote node (either a server or client) within the time
set here. (Enabled for socket services using FINS/TCP or TCP/IP only.)
Setting range: 0 to 65,535 minutes
This setting applies to the keep-alive setting for each connection set
with the FINS/TCP Setting button.

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

6-6-5 Auxiliary Area Allocation


The following table and descriptions cover the words and bits in the Auxiliary
Area of PLC memory that are related to the socket services.
Ethernet Status
Address Bit(s) Name Status Manipulated Unit operation Access
by
A45 0 to 13 Reserved --- --- --- Read only
14 Link Status ON Unit ON while a link is established between
Flag hub.
OFF Unit OFF when the link between hub is termi-
nated.
15 Reserved --- --- ---
A46 0 to 1 Reserved --- --- --- Read only
2 IP Address ON Unit ON if any of the following conditions
Setting Error apply to the IP address.
Flag • All bits in the host ID are 0 or 1.
• All bits in the network ID are 0 or 1.
• All bits in the subnet ID are 1.
• The IP address begins with 127 (0x7F)
OFF Unit OFF when the IP address is normal.
3 IP Address ON Unit On if the IP address table information is
Table Error incorrect.
Flag OFF Unit OFF when the IP address table is nor-
mal.
4 IP Router ON Unit ON if the IP router table information is
Table Error incorrect.
Flag OFF Unit OFF when the IP address table is nor-
mal.
5 DNS Server ON Unit ON when the following errors occur dur-
Error Flag ing DNS server operation:
• An illegal server IP address is set.
• A timeout occurs during communica-
tions with the server.
OFF Unit OFF when DNS server operation is nor-
mal.
6 Routing ON Unit ON if the routing table information is
Table Error incorrect.
Flag OFF Unit OFF when the routing table is normal.
7 to 10 Reserved --- --- ---
11 SNTP ON Unit ON when the following errors occur dur-
Server Error ing SNTP server operation:
• An illegal server IP address or host
name is set.
• A timeout occurs during communica-
tions with the server.
OFF Unit OFF when SNTP server operation is nor-
mal.
12 to Reserved --- --- ---
13
14 Address Dis- ON Unit ON if the remote IP address is set to
agreement automatic generation but the local IP
Flag address host number and FINS node
address do not agree.
OFF Unit OFF under all other circumstances.
15 Reserved --- --- ---

192
Socket Services Section 6-6

Address Bit(s) Name Status Manipulated Unit operation Access


by
A47 0 FINS/TCP ON Unit Turned ON by the Unit when a connection is Read only
Connection established.
Flag 1 OFF Unit Turned OFF by the Unit when the connection
is terminated.
1 FINS/TCP ON Unit Turned ON by the Unit when a connection is
Connection established.
Flag 2 OFF Unit Turned OFF by the Unit when the connection
is terminated.
2 FINS/TCP ON Unit Turned ON by the Unit when a connection is
Connection established.
Flag 3 OFF Unit Turned OFF by the Unit when the connection
is terminated.
3 to 15 Reserved --- --- ---

Ethernet Service Request


Address Bit(s) Name Status Manipulated Unit operation Access
by
A566 2 Socket ON User All sockets are forcibly closed when this Read/Write
Force-close bit turns ON.
Switch OFF Unit Turned OFF by Unit after sockets are
closed.

Socket Force-close Switch (Bit 2)


All UDP and TCP sockets used for socket services can be force-closed by turn-
ing ON this switch. This can be used for operations such as error processing.
Be careful not to force-close sockets during communications, or an error will
occur. After all sockets have been force-closed, the PLC will turn the switch
OFF again. Do not attempt to forcibly manipulate this switch before it is auto-
matically turned OFF by the PLC.
Ports used exclusively by the Ethernet Unit will not be closed.

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

Status of TCP/UDP Sockets 1 to 3


15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
A567 to A569

Data Received Flag Opening Flag

Results Storage Error Flag Receiving Flag

TCP/UDP Open Flag Sending Flag

Closing Flag

193
Socket Services Section 6-6

Bit Flag Status Manipulated Unit operation Access


by
0 Opening Flag ON Unit ON during open processing. (Turns Read only
ON when open request is received.)
OFF Unit OFF when open processing has
been completed.
1 Receiving Flag ON Unit ON during receive processing.
(Turns ON when receive request is
received.)
OFF Unit OFF when receive processing has
been completed.
2 Sending Flag ON Unit ON during send processing. (Turns
ON when send request is received.)
OFF Unit OFF when send processing has
been completed.
3 Closing Flag ON Unit ON during close processing. (Turns
ON when close request is received.)
OFF Unit OFF when close processing has
been completed.
4 to 12 (Not used.) --- --- --- ---
13 Data Received Flag ON Unit ON when data from a remote node Read only
has been received at an open TCP
socket.
OFF Unit OFF when receive processing has
been requested for an open TCP
socket.
14 Results Storage ON Unit ON if there is an error in storing the
Error Flag results when socket services are
used.
OFF Unit Turns OFF when the next request is
received.
15 TCP/UDP Open ON Unit ON when open processing has been
Flag completed.
OFF Unit OFF when close processing has
been completed. (Stays OFF for
abnormal open processing comple-
tion.)

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

Bit Switch Status Manipulated Unit operation Access


by
8 0 UDP Open Request ON User UDP socket opened when switch is turned Read/Write
Switch ON.
OFF Unit Unit turns OFF switch when open processing
has been completed (i.e., when a connection
has been made).
9 1 TCP Passive Open ON User Passive TCP socket opened when switch is
Request Switch turned ON.
OFF Unit Unit turns OFF switch when open processing
has been completed (i.e., when a connection
has been made).
10 2 TCP Active Open ON User Active TCP socket opened when switch is
Request Switch turned ON.
OFF Unit Unit turns OFF switch when open processing
has been completed (i.e., when a connection
has been made).
11 3 Send Request ON User Send processing executed when switch is
Switch turned ON.
(The protocol (TCP/UDP) is determined when
the socket is opened.)
OFF Unit Unit turns OFF switch when send processing
has been completed.
12 4 Receive Request ON User Receive processing executed when switch is
Switch turned ON.
(The protocol (TCP/UDP) is determined when
the socket is opened.)
OFF Unit Unit turns OFF switch when receive process-
ing has been completed.
13 5 Close Request ON User Close processing executed when switch is
Switch turned ON.
(The protocol (TCP/UDP) is determined when
the socket is opened.)
OFF Unit Unit turns OFF switch when close processing
has been completed.
14 6 Reserved --- --- --- ---
15 7 Reserved --- --- --- ---

6-6-6 Data Memory Area Allocations


The memory allocation about socket service is shown in the following dia-
gram. These data will be allocated to the DM area of the PLC.
Beginning word m = 32400

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

m+2 D32402 TCP Socket No. 3 Number of Bytes Received

m+3 D32403 Reserved

m+4 D32404 TCP Socket No. 1 Connection Status

m+5 D32405 TCP Socket No. 2 Connection Status

m+6 D32406 TCP Socket No. 3 Connection Status


m+7 D32407 Reserved
m+8
D32408 to D32417 Socket Services Parameter Area 1
m+17
m+18
D32418 to D32427 Socket Services Parameter Area 2
m+27
m+28
D32428 to D32437 Socket Services Parameter Area 3
m+37
m+38
D32438 to D32447 Reserved
m+47

TCP Socket No. (1 to 3): Number of Bytes Received


15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
m to m+2 Number of Bytes Received (0000 to 0400 hex)

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

TCP connection status

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

Socket Services Parameter Area 1 to 3


Offset Socket ... Socket
No. 1 No. 3 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
+0 m+8 ... m+28 Socket option UDP/TCP socket number (1 to 3)
+1 m+9 m+29 Local UDP/TCP port number (0000 to FFFF Hex)
+2 m+10 m+30 Remote IP address
m+11 m+31 (00000000 to FFFFFFFF Hex)
+4 m+12 ... m+32 Remote UDP/TCP port number (0000 to FFFF Hex)
+5 m+13 m+33 Number of send/receive bytes (0000 to 0400 Hex (1024))
+6 m+14 m+34 Send/receive data address
m+15 m+35 (Same as FINS variable area designation method.)
+8 m+16 m+36 Timeout value (0000 to FFFF Hex)
+9 m+17 ... m+37 Response code

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

Note W: Written by user


RW: Written by user at execution and then read for results at completion
R: Read by user for results at completion
---: Not used.

197
Socket Services Section 6-6

TCP Socket Services


Parameter No. of Range Socket service
words (decimal values in TCP TCP TCP TCP TCP
parentheses) passive active receive send close
open open
Socket option 1 Specified bit W W --- --- ---
UDP/TCP socket No. 0001 to 0003 hexadecimal W W W W W
(1 to 3)
Local UDP/TCP port 1 0000 to FFFF hexadecimal W RW --- --- ---
No. (0 to 65,535)
Remote IP address 2 00000000 to FFFFFFFF RW W --- --- ---
hexadecimal
(0.0.0.0 to 255.255.255.255)
Remote UDP/TCP 1 0000 to FFFF hexadecimal RW W --- --- ---
port No. (0 to 65,535)
Number of bytes to 1 0000 to 04D0 hexadecimal --- --- RW RW ---
send/ receive (0 to 1,024 bytes)
Send/Receive data 2 Memory area address --- --- W W ---
address
Time out time (Unit: 1 0000 to FFFF hexadecimal W --- W --- ---
100 ms) (0 to 65,535)
(0: No limit, 0.1 to 6,553.5 s)
Response code 1 --- R R R R R

Note W: Written by user


RW: Written by user at execution and then read for results at completion
R: Read by user for results at completion
n---: Not used.

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

Remote IP Address Specify the IP address of the remote device.


• Offset +2 in the Socket Service Parameter Area contains the upper bytes
of the Remote IP Address, and offset +3 contains the lower bytes.
Example: The contents of offsets +2 and +3 would be as shown below
when the Remote IP Address is 196.36.32.55 (C4.24.20.37 hexadeci-
mal).
+2: C424
+3: 2037
• This parameter is not used when making a receive request for a UDP
socket. The remote IP address will be stored with the response data and
will be written as the Remote IP Address in the Socket Service Parameter
Area.
• When opening a passive TCP socket, the combination of the remote IP
address and the remote TCP port number can be used to affect process-
ing as shown in the following table.
Remote IP Remote TCP Processing
Address Port No.
0 0 All connection requests accepted.
0 Not 0 Connection requests accepted only for the same
port number.
Not 0 0 Connection requests accepted only for the same
IP address.
Not 0 Not 0 Connection requests accepted only for the same
port number and IP address.

If the Remote IP Address is set to 0, a connection can be made to any remote


node and the remote IP address of the node that is connected will be stored
as the Remote IP Address in the Socket Service Parameter Area. If a specific
remote IP address is set, then a connection can be made only to the node
with the specified address.
If the Remote TCP Port No. is set to 0, a connection can be made to any
remote node regardless of the TCP port number it is using. If a specific
remote TCP port number is set, then a connection can be made only to a
node using the specified TCP port number.
Remote UDP/TCP Port No. Specify the UDP or TCP port number used by the remote device.
• This parameter is not used when making a receive request for a UDP
socket. The remote UDP/TCP port number will be stored with the
response data and will be written as the Remote UDP/TCP Port No. in the
Socket Service Parameter Area.
• When opening a passive TCP socket, the combination of the remote IP
address and the remote TCP port number can be used to affect process-
ing as shown in the table for the Remote IP Address, above. If the Remote
UDP/TCP Port No. is set to 0, the UDP/TCP port number of the remote
device will be written as the Remote UDP/TCP Port No. in the Socket Ser-
vice Parameter Area.
Time Out Time Set the time limit in units of 0.1 s for completion of communications from the
time that the Receive Request Switch (TCP or UDP) or the TCP Passive
Open Request Switch is turned ON. A response code of 0080 hexadecimal
(timeout) will be stored if communications time out. If 0 is set, the requested
service will not be timed.

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)

The following specifications can be used.


Area Word address Area Word address
designation (hexadecimal)
(hexadecimal)
CIO, HR, CIO 0000 to 6143 B0 0000 to 17FF
and AR HR H000 to H511 B2 0000 to 01FF
Areas
AR A448 to A959 B3 01C0 to 03BF
DM Area DM D00000 to D32767 82 0000 to 7FFF

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

UDP Socket Receive Request


Response Meaning
code
0000 Normal end
0302 CPU Unit error; cannot execute.
1100 Number of bytes to receive is 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 receive request.
2210 The specified socket is not open.
2211 Unit is busy; cannot execute service.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.
0080 Receive request timed out.
0081 The specified socket was closed during reception processing.

UDP Socket Send Request


Response Meaning
code
0000 Normal end
0302 CPU Unit error; cannot execute.
1100 Number of bytes to send is not in allowable range or the remote
IPaddress is 0.
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 open.
2211 Unit is busy; cannot execute.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.
003E Internal buffer cannot be obtained due to high reception traffic
(ENOBUFS).
004C The network ID is incorrect or the remote IP address is incor-
rect(EADDRNOTAVAIL)
004E The network ID is not in the IP router table, router settings are
incorrect, or the remote IP address is incorrect (ENETUNREACH).
0051 The router settings are incorrect or the remote IP address is incor-
rect (EHOSTUNREACH).
0081 The specified socket was closed during send processing.

UDP Socket Close Request


Response Meaning
code
0000 Normal end
0302 CPU Unit error; cannot execute.
2210 The specified socket is not open.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.

201
Socket Services Section 6-6

TCP Socket Passive 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 openrequest.
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.
0045 Error in communications with remote node (ECONNABORTED).
0049 The same TCP port number has been specified more than
once(EADDRINUSE).
004A (See note.) Error (ECONNREFUSED).
004B (See note.) Error in communications with remote node (ECONNRESET).
0053 Error in communications with remote node (ETIMEDOUT) or
remotenode does not exist.
0080 Open request timed out.
0081 The specified socket was closed during open processing.
0082 Connection could not be established with specified remote node.

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

TCP Socket Receive Request


Response Meaning
code
0000 Normal end
0302 CPU Unit error; cannot execute.
1100 Number of receive bytes 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 receive request.
2210 Specified socket has not been connected.
2211 Unit is busy; cannot execute.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.
0045 (See note.) Error in communications with remote node (ECONNABORTED).
0053 Error in communications with remote host (ETIMEDOUT).
0080 Receive request timed out.
0081 The specified socket was closed during receive processing.

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

TCP Socket Close Request


Responsecode Meaning
0000 Normal end
0302 CPU Unit error; cannot execute.
2210 The specified socket is not been connected.
2607 Specified Socket Service Parameter Area is already being used
foranother socket.

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).

6-6-7 Socket Application Example


TCP/IP Communications Programming Example
The following programming example illustrates transferring 100 bytes of
databetween an Ethernet Unit and a host computer using TCP/IP commu-
nica-tions.
System Configuration The programming example uses the following system configuration. For the
TCP connection, the Ethernet Unit uses a passive open and the host com-
puter uses an active open.
Host computer Ethernet Unit
PLC

IP address: 192.168.250.5 IP address: 192.168.250.1


Port number: 4096 Port number: 4096

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).

Execution bits turned OFF


Processing in
host computer

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

Send data, 100 bytes (100 = 0064 Hex)

DM00049
15 00
DM01000

Receive data, 100 bytes (100 = 0064 Hex)

DM01049

WR Area
15 03 02 01 00

TCP
W0 Receive TCP TCP TCP
Bit Send Bit Close Bit Open Bit

TCP TCP TCP


W1 Receive TCP Send Close Open
Error Flag Error Flag
Error Flag Error Flag

TCP TCP TCP TCP


Receiving Sending Closing Opening
W2
Flag Flag Flag Flag

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

Continued from previous page.


W0.02 TCP Send
@RSET When the TCP Send Bit (W0.02) turns ON, the TCP Send Error
W1.02 Flag (W1.02) is turned OFF and the TCP Sending Flag (W2.02) is
@SET turned ON to initialize processing.
W2.02
W0.02 W2.02
MOV(021) When the TCP Sending Flag (W2.02) turns ON, the following
#1 parameters are written to the parameter area for socket number 1
D32408 D32408: 0001 Hex = UDP/TCP socket No. 1
MOV(021) D32413: 0064 Hex = No. of send/receive bytes is 100
#64 D32414 and D32415:
D32413 8200 0000 Hex =
MOV(021) Send/receive data address D00000
#8200
D32414

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

W0.02 W2.02 A571.03


<>(305) @SET If the Send Request Switch (A571.03) turns OFF while the TCP
D32417 W1.02 Sending Flag (W2.02) is OFF, the contents of the response code
#0 (D32417) in the Socket Service Pa-rameter Area is checked, and
W0.02 W2.02 A571.03 if it is not 0000 Hex (normal end), the TCP Send Error Flag
RSET
(W1.02) is turned ON.
W0.02 After the execution results have been checked, the TCP
W0.03
Send Bit (W0.02) is turned OFF.
@RSET
A567.13 W1.03

=(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


After the parameter has been set, the Receive Request Switch
<>(305) SET (A571.04) is turned ON and the TCP Receiving Flag (W2.03) is
D32417 W1.03 turned OFF.
#0

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy