0% found this document useful (0 votes)
372 views

MTCP Server NJNX e

Uploaded by

cardonPT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
372 views

MTCP Server NJNX e

Uploaded by

cardonPT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Function Block

Reference MTCP_Server_NJNX OMRON ELECTRONICS S.A.S.


Revision 2.4 3 parvis de la Gare
94130 Nogent sur Marne
Author JP Viskovic
Date 28/02/2020
+ Support http://support-omron.fr/

Modbus TCP Server for NJ-NX Controller

Function Modbus TCP server for Built-in Ethernet NJ-NX Controller


Server

File MTCP_Server_NX.slr
Conditions The FB Modbus TCP Server provides some read/write features in accordance with the
of use specifications defined by the Modbus organization.

The Modbus TCP Server 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.

Principe The function block MTCP_Server_NJNX switch to LISTEN mode waiting for a Modbus
TCP Client connection when Start input is activated.
We recommend using the FB in a periodical task to not overload the primary task.
List of functions supported by MTCP_Server_NJNX:
Code Modbus Function
0x01 Read Coils
0x02 Read Discret Inputs
0x03 Read Holding Registers
0x04 Read Input Registers
0x05 Write Single Coil
0x06 Write Single Register
0x08 Echo Back
0x10 Write Multiple Registers
0x15 Write Multiple Coils
0x17 Read Write Multiple Registers

Start NJ/NX port 1 : _EIP_EtnOnlineSta


condition NX102 port 2 : _EIP2_EtnOnlineSta
Function Block MTCP_Server_NJNX Modbus TCP Server for NJ and NX Controller

1- I/O variable of MTCP_Server_NJNX

Input variable
Name type range Description
Start Bool OFF, ON Server Activation
Local_TcpPort UINT 1-65535 Local TCP port Number (défaut 502)
ConnectionTimeout TIME Delay of no activity. Client is gone and server
should be restarted.
Set to 0, keep alive function used
Reset_Counter Bool OFF, ON ON: Reset the SdRcv_Counter to zero

Input/output Variables
Name type range Description
Registers Array of 0-FFFF Register area
1024 Words ARRAY[0..1023] OF WORD
Coils Array of OFF, ON Coil area
1024 bool ARRAY[0..1023] OF BOOL

Output Variables
Name type Range Description
Connected Bool OFF, ON ON : client is connected
Error Bool OFF, ON Error flag
ErrorID UINT 0 - FFFF Error Code returned by the socket or
Modbus TCP server (see error code list
below).
TCP_Status _eCONNECTION_STATE Enum _CLOSED
_LISTEN
_SYN SENT
_SYN RECEIVED
_ESTABLISHED
_CLOSE_WAIT
_FIN WAIT1
_CLOSING
_LAST ACK
_FIN WAIT2
_TIME WAIT
IP_Client String[24] w.x.y.z IP address of connected client
Port_Client UINT 0-65535 Port number of connected client
SdRcv_Counter UDINT 0- Number of response sent
4294967295

2- Error Code returned in ErrorID

Code Description
0001 ILLEGAL FUNCTION
Modbus
0002 ILLEGAL DATA ADDRESS
Exception
0003 ILLEGAL DATA VALUE
2000 Local IP Address Setting Error
2001 TCP/UDP Port Already in Use
2002 Address Resolution Failed
2003 Socket Status Error
2004 error Local IP Address Not Set
2006 Socket Timeout
2007 Socket Handle Out of Range
2008 Socket Communications Resource Overflow

JPV 28/02/2020 Page 2/7


Function Block MTCP_Server_NJNX Modbus TCP Server for NJ and NX Controller

3- Keep Alive and Linger option

In the event of an accidental break in the Ethernet connection, the server does not
know whether the client is still connected.
You can execute cyclic readings to control the presence of the client or define a
maximum period of inactivity with the input ConnectionTimeout of the function block
or even use the Keep Alive option so that the server regularly interrogates the client
by sending a request [TCP Keep-Alive] according to the delay defined in this option
(here 10s) then after 20s the port is released for a new connection.

When using multiple clients involving fast connections and disconnections, the Linger
option allows the Ethernet socket to abruptly close the connection via a [RESET]
rather than following the standard procedure FIN_WAIT 1 then FIN WAIT2.

4- Checking, debugging your Modbus TCP project.

To emulate a Modbus TCP client, you can use the utility software Etherway free to
download on:
https://www.support-omron.fr/details/logiciel.php?id=2017-07-28%20-%2015-34-
21%20-%20636541960

JPV 28/02/2020 Page 3/7


Function Block MTCP_Server_NJNX Modbus TCP Server for NJ and NX Controller

Precautions in Using Socket Services


Precautions for UDP and TCP Socket Services
• Communications processing are sometimes delayed when multiple functions of the built-in Ether-
Net/IP port are used simultaneously or due to the contents of the user program.
• Communications efficiency is sometimes reduced by high communications traffic on the network line.
• The close processing for a close request instruction discards all of the buffered send and receive
data
for the socket. For example, send data from a send request instruction immediately before the close
processing is sometimes not sent.
• After a socket is open, the built-in EtherNet/IP port provides a receive buffer of 9,000 bytes per TCP
socket and 9,000 bytes per UDP socket to enable data to be received at any time. If the receive buffer
is full, data received by that socket is discarded. Make sure that the user application always executes
receive requests to prevent the internal buffer from becoming full.

Precautions for UDP Socket Services


• The destination IP address can be set to a broadcast address for a UDP socket to broadcast data to
all nodes on the network. However, in this case, the maximum length of send data is 1,472 bytes.
Data lengths broken into multiple fragments (1,473 bytes or more in UDP) cannot be sent.
• For UDP socket, controls to confirm the reliability of communications, such as the confirmation of
send data, are not performed. To improve the reliability of communications when you use UDP
sockets,
make sure the user program confirms that data is sent and resends data when necessary.

Precautions for TCP Socket Services


• If the TCP socket is closed on the remote node without warning during communications (i.e., if the
connection is closed), the socket at the local node must also be closed. You can use the Read TCP
Socket Status instruction (SktGetTCPstatus) to see if the connection is closed. Immediately close the
socket at the local node if the TCP socket at the remote node is closed.
• If the remote node’s TCP socket closes without warning, the data to send may remain in the buffer at
the local node. The remaining data is discarded in the local node’s TCP close processing. The steps
that are required in applications to avoid this include sending data from the sending node that permits
closing and closing the socket only after checking the remote node.
• While open processing is performed for a TCP socket, a port that was closed first cannot be opened
again for 60 seconds from the time the close processing is performed for the remote socket. However,
this is not true if you specified 0 (automatic assignment by the Unit) as the port for the SktTCPConnect
instruction.
• You can use Connect from another socket to open a connection to a socket that was opened with
Accept. A connection is not opened if you try to use Connect from another socket to open a
connection
to a socket that was opened with Connect. Also, a connection is not opened if you attempt to use
Accept from another socket to open a socket that was opened with Accept. Furthermore, you cannot
use Connect from more than one other node to establish multiple connections with a single TCP
socket that was opened with Accept on the built-in EtherNet/IP port.
• You can use the keep-alive function for TCP sockets at the built-in EtherNet/IP port. The keep alive
function checks whether a connection is normally established when no data is sent or received for a
certain period on the communications line where the connection was established. The built-in Ether-
Net/IP port responds to checks from other nodes even if keep alive is not specified.

JPV 28/02/2020 Page 4/7


Function Block MTCP_Server_NJNX Modbus TCP Server for NJ and NX Controller

Modbus protocol
Read Multiple Coils Fn01

Example: read 19 coils (20 to 38)


Request Response
Data Data
Function Code 0x01 Function Code 0x01
Starting Address(H) 0x00 Byte Count 0x03
Starting Address(L) 0x14 Coil Status 27-20 0xCD
Quantity of Coils(H) 0x00 Coil Status 35-28 0x6B
Quantity of Coils(L) 0x13 Coil Status 38-36 0x05

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.
Attention : In the MTCP_Server NJNX library, coil addresses start at address 0000.

Reads registers in I/O memory area Fn03

Example: read 3 words (DM 1000 to DM 1002)


Request Response
Data Data
Function Code 0x03 Function Code 0x03
Starting Address(H) 0x03 Byte Count 0x06
Starting Address(L) 0xE8 Register Value(H)DM1000 0xAB
Quantity of Registers(H) 0x00 Register Value(L) DM1000 0x12
Quantity of Registers(L) 0x03 Register Value(H)DM1001 0x56
Register Value(L) DM1001 0x78
Register Value(H)DM1002 0x97
Register Value(L) DM1002 0x13

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

Writes single coil Fn05

Example: write 1 coil. (0002.02 ON)


Request Response
Data Data
Function Code 0x05 Function Code 0x05
Output Address(H) 0x00 Output Address(H) 0x00
Output Address(L) 0x22 Output Address(L) 0x22
Output Value(H) 0xFF Output Value(H) 0xFF
Output Value(L) 0x00 Output Value(L) 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 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.

JPV 28/02/2020 Page 5/7


Function Block MTCP_Server_NJNX Modbus TCP Server for NJ and NX Controller

Writes single register Fn06

Example: write &h3AC5 to register 2000.


Request Response
Data Data
Function Code 0x06 Function Code 0x06
Register Address(H) 0x07 Register Address(H) 0x07
Register Address(L) 0xD0 Register Address(L) 0xD0
Register Value(H) 0x3A Register Value(H) 0x3A
Register Value(L) 0xC5 Register Value(L) 0xC5

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
2000 3 A C 5

Writes registers Fn10

Example: write 2 words into registers 1000-1001.


Request Response
Data Data
Function Code 0x10 Function Code 0x10
Starting Address(H) 0x03 Starting Address(H) 0x03
Starting Address(L) 0xE8 Starting Address(L) 0xE8
Quantity of Registers(H) 0x00 Quantity of Registers(H) 0x00
Quantity of Registers(L) 0x02 Quantity of Registers(L) 0x02
Byte Count 0x04
Registers Value(H) 0x3A
Registers Value(L) 0xC5
Registers Value(H) 0x97
Registers Value(L) 0x13

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

Write multiple coils Fn15

Example : write 10 coils ( xxxx xx11 1100 1101) coils 20 to 29.(X = ignored.)
Request Response
Data Donnée
Function Code 0x0F Function Code 0x0F
Starting Address(H) 0x00 Starting Address(H) 0x00
Starting Address(L) 0x14 Starting Address(L) 0x14
Quantity of coils(H) 0x00 Coil quantity (H) 0x00
Quantity of coils(L) 0x0A Coil quantity (L) 0x0A
Data byte quantity 0x02
1rst value (low byte) 0x3A
2nd value (high byte) 0x01

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.

Attention : In the MTCP_Server NJNX library, coil addresses start at address 0000.

JPV 28/02/2020 Page 6/7


Function Block MTCP_Server_NJNX Modbus TCP Server for NJ and NX Controller

Read and Write multiple registers Fn17

Example: read registers 1 & 2 (1001-2002) and write CAFE into register 0003.
Request Response
Data 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

JPV 28/02/2020 Page 7/7

You might also like