MTCP CP1L Server E
MTCP CP1L Server E
File MTCP_CP1L_Server.zip
Conditions
of use The FB Modbus TCP server provides some read/write features in accordance with the
specifications defined by the Modbus organization.
Restrictions :
The Modbus TCP Client function block is offered 'as is' and may serve as a basis for
development.
Users should previously test its adequacy to the final application.
Omron could not be held responsible in case of malfunction.
Function Block MTCP_CP1L_Server Modbus TCP Server
TCP TIME-WAIT:
When a TCP connection is closed, the socket pair is placed in a known as TIME-WAIT
state, which ensures that a new connection does not use the same protocol, source
IP address, destination IP address, source port and destination port, until a period of
time sufficient flows to ensure that any segment that may have been incorrectly
routed or delayed are not delivered unexpectedly. The duration of the interval during
which the socket pair cannot be reused is specified in RFC 793 as equal to 2 MSL
(twice the maximum lifetime of a segment), or four minutes (CP1L 2mn) .
To avoid this delay, use another local port on the client side (the server is fixed on
port 502).
If the disconnection occurs on client side, the CP1L cannot detect it.
Then a ‘NoActivity_Delay’ has been added to restart the server in case of no
received request during the connection.
Input Variable
Name type Range Description
EN Bool OFF, ON Enable FB execution
LocalPort UINT 1-65535 Local port number (default value 502)
NoActivity_Dealy UINT 0-9999 0: No control, function deactivated
>0: Delay to restart the server in case of no request
received during that time (when connected only)
StartServer Bool OFF, ON ON: open socket in passive mode (listen)
OFF: close the socket
Output Variables
Name type Range Description
ENO Bool OFF, ON Server operational and listening for a client connection
Connected Bool OFF, ON Client connected (last field of IP address)
IP_Client UINT 0-9999
Error_Code Bool OFF, ON See code error list bellow
Except_Counter UINT 0 - FFFF Counter of exception error
Recv_Counter UINT 0 - FFFF Counter of received request (any)
Socket services Error Codes are returned prior to Modbus exception error
Etherway utility software can help to debug Modbus TCP communication and can be found here:
https://www.support-omron.fr/rechercher/?r=etherway
ANNEXE
Modbus protocol
I/O memory area (CIO) Read Multiple Coils
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0CH 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1CH 31 1 30 0 29 1 28 1 27 1 26 1 25 0 24 0 23 1 22 1 21 0 20 1 19 18 17 16
2CH 47 46 45 44 43 42 41 40 39 38 1 37 0 36 1 35 0 34 1 33 1 32 0
3CH 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
Italic characters show the ON/OFF(1/0) status of its bit condition.
DM 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1000 A B 1 2
1001 5 6 7 8
1002 9 7 1 3
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0CH 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JPV 11/12/2019 Page 4/6
Function Block MTCP_CP1L_Server Modbus TCP Server
1CH 31 1 30 0 29 1 28 1 27 1 26 1 25 0 24 0 23 1 22 1 21 0 20 1 19 18 17 16
2CH 47 46 45 44 43 42 41 40 39 38 1 37 0 36 1 35 0 34 1 33 1 32 0
3CH 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
Italic characters show the ON/OFF(1/0) status of its bit condition.
DM 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
2000 3 A C 5
2001
2002
Writes registers.
DM 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1000 3 A C 5
1001 9 7 1 3
Example: In the case of writing 10 bits ( xxxx xx11 1100 1101) to CIO 0001.04.
(X = ignored.)
Request Response
Data Data
Function Code 0x0F Function Code 0x0F
Starting Address(H) 0x00 Starting Address(H) 0x00
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0CH 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1CH 31 0 30 0 29 0 28 1 27 0 26 0 25 1 24 1 23 1 22 0 21 1 20 0 19 0 18 0 17 0 16 0
Italic characters show the ON/OFF(1/0) status of its bit condition.
Example: read registers 1 & 2 (1001-2002) and write CAFE into register 0003.
Requête Réponse
Donnée Donnée
Function Code 0x17 Fonction Code 0x17
Starting Address(H) to read 0x00 Nbre of byte 0x04
Starting Address(L) to read 0x01 Valeur du register 1 (poids faible) 0x10
Quantity of Registers(H) to read 0x00 Valeur du registre 1 (poids fort) 0x01
Quantity of Registers(L) to read 0x02 Valeur du register 2 (poids faible) 0x20
Starting Address(H) to write 0x00 Valeur du registre 2 (poids fort) 0x02
Starting Address(L) to write 0x03
Nbre of registers (H) to write 0x00
Nbre of registers (L) to write 0x01
Nbre of byted’octets à écrire 0x02
1ère valeur (poids fort) 0xCA
1ère valeur (poids faible) 0xFE
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0000 3 A C 5
0001 1 0 0 1
0002 2 0 0 2
0003 C A F E