Академический Документы
Профессиональный Документы
Культура Документы
35012293.02
www.schneider-electric.com
35012293 11/2008
Table of Contents
Safety Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 1 Modbus Slave Device Driver . . . . . . . . . . . . . . . . . . . . .
Modbus Slave (RTU) System Structure . . . . . . . . . . . . . . . . . . . . . . . . Cable Diagrams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modbus Slave TCP/IP System Structure . . . . . . . . . . . . . . . . . . . . . . . Supported Equipment Variable Addresses . . . . . . . . . . . . . . . . . . . . . . Consecutive Equipment Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . Environment Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I/O Manager Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Driver Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Equipment Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variable Address Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 7 11
12 17 24 25 30 31 34 35 37 41
47
48 51 54
55
56 59 62 65
Chapter 4 Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Modbus function codes and exception error codes. . . . . . . . . . . . . . . .
67
67
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
71
35012293 11/2008
35012293 11/2008
Safety Information
Important Information
NOTICE Read these instructions carefully, and look at the equipment to become familiar with the device before trying to install, operate, or maintain it. The following special messages may appear throughout this documentation or on the equipment to warn of potential hazards or to call attention to information that clarifies or simplifies a procedure.
35012293 11/2008
PLEASE NOTE Electrical equipment should be installed, operated, serviced, and maintained only by qualified personnel. No responsibility is assumed by Schneider Electric for any consequences arising out of the use of this material. 2008 Schneider Electric. All Rights Reserved.
35012293 11/2008
At a Glance
Document Scope This documentation presents Modbus Slave device driver for Magelis XBT G/XBT GC/XBT GK/XBT GT/iPC/XBTGTW. Validity Note The data and illustrations found in this book are not binding. We reserve the right to modify our products in line with our policy of continuous product development. The information in this document is subject to change without notice and should not be construed as a commitment by Schneider Electric.
35012293 11/2008
Related Documents
WARNING
LOSS OF CONTROL The designer of any control scheme must consider the potential breakdown modes of control paths and, for certain critical control functions, provide a means to achieve a safe state during and after a path breakdown. Examples of critical control functions are emergency stop and overtravel stop. Provide separate or redundant control paths for critical control functions. System control paths may include communication links. Consideration must be given to the implications of unanticipated transmission delays or misoperation of the link. * Individually and thoroughly test each implementation of Magelis XBT G/XBT GC/XBT GK/XBT GT/iPC/XBTGTW before placing them in service. Failure to follow these instructions can result in death, serious injury, or equipment damage. * For additional information, refer to NEMA ICS 1.1 (latest edition), Safety Guidelines for the Application,Installation, and Maintenance of Solid State Control .
Title of Documentation Vijeo Designer User manual Vijeo Designer Tutorial Magelis XBT GK/XBT GT Modbus (RTU) driver Reference Number Included in the Vijeo Designer CDROM Included in the Vijeo Designer CDROM Included in the VijeoDesigner CDROM Included in the VijeoDesigner CDROM Included in the VijeoDesigner CDROM
You can download these technical publications and other technical information from our website at www.schneider-electric.com.
35012293 11/2008
User Comments We welcome your comments about this document. You can reach us by e-mail at techcomm@schneider-electric.com.
35012293 11/2008
10
35012293 11/2008
1
Subject of the Chapter This chapter explains how to connect the target machine with Modbus RTU and Modbus TCP/IP equipment. For information about how to use the Vijeo-Designer software, please refer to the Vijeo-Designer Online Help. The types of target machines that are compatible with Vijeo-Designer depend on the version of Vijeo-Designer. For information about the compatibility of target machines, please refer to the Vijeo-Designer Online or User Manual help. NOTE: Target machines mean Magelis XBT G/XBT GC/XBT GK/XBT GT/iPC/XBTGTW products. What's in this Chapter? This chapter contains the following topics:
Topic Modbus Slave (RTU) System Structure Cable Diagrams Modbus Slave TCP/IP System Structure Supported Equipment Variable Addresses Consecutive Equipment Addresses Environment Setup I/O Manager Configuration Driver Configuration Equipment Configuration Variable Address Configuration Page 12 17 24 25 30 31 34 35 37 41
35012293 11/2008
11
Modbus Slave
12
35012293 11/2008
Modbus Slave
Connection XBT G The following table describes the basic system setup for connecting the target machine to Modbus RTU equipment.
Protocol Modbus RTU CPU Link I/F Comm.Format RS-485 XBT G Connector Com1 DSUB25 + XBT ZG999 Com1 DSUB25 + XBT ZG999 Com1 DSUB25 + XBT ZG999 Com1 DSUB25 + XBT ZG999 Com2 DSUB9 Diagram Cable Diagram 3 (see page 18) Cable Diagram 1 (see page 18) Cable Diagram 1 (see page 18) Cable Diagram 4 (see page 18) Cable Diagram 5 (see page 19) Cable Diagram 2 (see page 18) Cable Diagram 6 (see page 19)
TSX37 Micro Modbus Slave auxiliary terminal port Quantum CPUS Modbus port Sub-D9
RS-232C
Momentum
RS-232C
TSX57 Premium
SCY2160
RS-485
Advantys STB
NOTE: To connect XBT G to TSX-SCG116, use XBT ZG999 + XBT Z928 To connect XBT G to TSX17, use XBT ZG999 + XBT Z917 To connect XBT G to V4 CPU through TSXLES64/74, use XBT ZG999 + XBT Z948 on HE13/14
35012293 11/2008
13
Modbus Slave
Connection XBT GT1000/1005 series The following table describes the basic system setup for connecting the target machine to Modbus RTU equipment.
Protocol Modbus RTU CPU Micro Link I/F Modbus Slave auxiliary terminal port CPUs Modbus port Comm.Format RS-485 XBT GT Connector Com1 RJ45 Diagram Cable Diagram 7 (see page 20) Cable diagram 12 (see page 21) Cable diagram 10 (see page 20) Cable Diagram 11 (see page 21) Cable Diagram 8 (see page 20) Cable Diagram 11 (see page 21) Cable Diagram 9 (see page 20)
Momentum
RS-232C
SCY2160 D-Sub25
RS-485
SCY2160 SCP114
RS-485
Com1 RJ45
RS-485
Com1 RJ45
Connection XBT GK series, XBT GT2000 series or higher The following table describes the basic system setup for connecting the target machine to Modbus RTU equipment.
14
35012293 11/2008
Modbus Slave
CPU Micro
Diagram Cable Diagram 17 (see page 22) Cable diagram 18 (see page 23) Cable Diagram 13 (see page 21) Cable Diagram 14 (see page 21) Cable Diagram 10 (see page 20) Cable Diagram 15 (see page 22) Cable Diagram 8 (see page 20) Cable diagram 11 (see page 21) Cable diagram 9 (see page 20) Cable Diagram 16 (see page 22)
Com1 DSUB9 + XBT ZG909 Quantum CPUS Modbus port Sub-D9 CPUs Modbus port RS-232C Com1 DSUB9 + XBT ZG919 Com1 D-Sub-D9 + XBT ZG919 Com2 RJ45 + XBT ZG939 Com1 DSUB9 +XBT ZG909 Any Modbus Equipment Modbus HUB TSXPACC01 Socket subscriber Modbus-T RS-485 COM2 RJ45
Momentum
RS-232C
Premium
SCY2160
RS-485
RS-485
Connection XBT GC 2000 series The following table describes the basic system setup for connecting the target machine to Modbus RTU equipment.
35012293 11/2008
15
Modbus Slave
CPU Micro
Link I/F Modbus Slave auxiliary terminal port CPUS Modbus port Sub-D9 CPUs Modbus port
Comm. For- XBT GT Connector mat RS-485 Com1 DSUB9 + XBT ZG909 Com1 DSUB9 + XBT ZG919 Com1 D-Sub-D9 + XBT ZG919 Com1 DSUB9 +XBT ZG909 Com1 DSUB9 + XBT ZG909
Diagram Cable diagram 18 (see page 23) Cable Diagram 13 (see page 21) Cable Diagram 14 (see page 21) Cable Diagram 15 (see page 22) Cable Diagram 16 (see page 22)
Quantum
RS-232C
Momentum
RS-232C
Premium
SCY2160
RS-485
RS-485
16
35012293 11/2008
Modbus Slave
Cable Diagrams
Overview Schneider Electric recommends using the connection schemes in the following diagrams, as specified in the preceding connection tables. NOTE: Ensure that the equipment is properly grounded as indicated in the user manual and follows all applicable country standards.
35012293 11/2008
17
Modbus Slave
18
35012293 11/2008
Modbus Slave
Diagram 5 XBT G series, XBT GK series, XBT GT2000 series or higher, XBT GC series RS 232C
NOTE: For point to point connections, connect the XBT Z to the RJ45 equipments connector. Diagram 6 is using RS485 2 Wires bus. For the XBT Z938-V2, make sure that this exact reference is written on the cable.
35012293 11/2008
19
Modbus Slave
20
35012293 11/2008
Modbus Slave
35012293 11/2008
21
Modbus Slave
22
35012293 11/2008
Modbus Slave
35012293 11/2008
23
Modbus Slave
24
35012293 11/2008
Modbus Slave
35012293 11/2008
25
Modbus Slave
WARNING
UNINTENDED EQUIPMENT OPERATION Design your system to avoid conflicting write processes between the target machine and PLC program. Values on the PLC and the target machine will be incorrect if: the target machine and PLC program attempt to simultaneously write to the same register. PLC programs or other devices write 16-bit word values to registers being accessed in a bitwise manner. Failure to follow these instructions can result in death, serious injury, or equipment damage. The following table lists the equipment variable address range if you have selected the IEC61131 Syntax check box.
Variable %Mi %MWi:Xj Bit Address i = 0 to 65535 i = 0 to 65535 j = 0 to 15 Word Address --Note Read/Write access. j is a bit index with the following convention: 0 for the least significant bit and 15 for the most significant bit. Read/Write access. When you write to one of these bit addresses, the target machine reads the entire word, sets the defined bit, then returns the new word address to the PLC. If the ladder program writes data to this word value during the bit read/write process, the resulting data may be incorrect. Read/Write access. Read/Write access. To fit with equipment variable coding, the most significant byte could be chosen by the software (see page 35).
----
Non IEC Equipment variable address range The following table lists the equipment variable address range if you havent selected the IEC61131 Syntax check box.
26
35012293 11/2008
Modbus Slave
Variable Coils (C) Discrete Inputs Single word Input Registers Single word Holding Registers
Note Read/Write access. Read-only Read-only Read/Write access. When you write to one of these bit addresses, the target machine reads the entire word address, sets the defined bit, then returns the new word address to the PLC. If the ladder program writes data to this word address during the bit read/write process, the resulting data may be incorrect. Read-only To fit with equipment variable coding, the most significant byte could be chosen by the software (see page 35). Read/Write access. To fit with equipment variable coding, the most significant byte could be chosen by the software (see page 35).
30001,0365536,15
30001-365535
40001,0465536,15
40001-465535
Variable mapping
WARNING
UNINTENDED EQUIPMENT OPERATION Set up the ASCII Display byte order or the Double Word word order in the target machine to match the equipment order. If the orders are different, values on the PLC and the target machine will be wrong. Failure to follow these instructions can result in death, serious injury, or equipment damage. The word (16-bit) is managed as follows: least significant = byte n most significant = byte n + 1 (Check that the connected equipment uses the same format).
35012293 11/2008
27
Modbus Slave
Double words (32-bit integers or floating point values) are managed as follows: If the High word first Equipment Configuration (see page 35) option is selected: most significant = word n least significant = word n + 1 (Check that the connected equipment uses the same format.) 16-bit and 32-bit data, High and Low example.
NOTE: If Low word first Equipment Configuration (see page 35) is selected, the most significant word and the least significant word are inverted. For example to be consistent with Premium PLC format use the value Low word first. The string is managed as follows: Inside PLCs a string is usually an array of words for which every word contains two characters (one character per byte). For example the HELLO! string representation is the following:
Word order First word Second word Third word Most significant byte E L ! Least significant byte H L O
If Low byte first Equipment Configuration (see page 35) option is selected the string displayed on the target machine is: HELLO!. If High byte first Equipment Configuration (see page 35) option is selected the string displayed on the target machine is: EHLL!O.
28
35012293 11/2008
Modbus Slave
IEC equivalences The following table gives the equivalences between the Modbus syntax and the IEC61131 syntax.
Variable Type Modbus address syntax Format Internal coils and Output coils Holding register (word) Holding register (word bit) Holding register (double word) Holding register (float) Holding register (string) 00001+i 40001+i 40001+i,j (2) 40001+i 40001+i 40001+i Range i=0 to 65535 i=0 to 65535 i=0 to 65535 j=0 to 15 i=0 to 65534 i=0 to 65534 First element 00001 (1) 40001 40001,0 IEC61131 syntax Format %Mi %MWi %MWi:Xj Range i=0 to 65535 i=0 to 65535 i=0 to 65535 j=0 to 15 i=0 to 65534 i=0 to 65534 First element %M0 %MW0 %MW0:X 0 %MD0 %MF0
40001 40001
legend: (1): Leading zeros "00001" must be preserved (2): j is a bit index with the following convention: 0 for the least significant bit and 15 for the most significant bit. (3): k is equal to 65535 - string length / 2 rounded to the upper value. For instance with a 11 characters string weve got 65535 - 6 = 65529.
NOTE: The two areas 10000 and 30000 are not accessible with IEC syntax.
35012293 11/2008
29
Modbus Slave
30
35012293 11/2008
Modbus Slave
Environment Setup
Overview The following table lists the serial communication settings, recommended by Schneider Electric, for the target machine slave and equipment. Make sure these settings match the Modbus (RTU) equipment. For details, see Driver Configuration (see page 35) and Equipment Configuration (see page 37).
35012293 11/2008
31
Modbus Slave
RS-485 settings
Target Machine (Slave) Driver Serial Inter- RS-485 face Flow Control Transmission Speed Slave Equipment Address Parity Bit Stop Bit None 19200 bps 1 Equipment (Master) Connection Format -Baud Rate -19200 bps RS-485
Even 1 bit
Even 1 bit
Data Length 8 bit TX Wait Time Default value Equipment IEC61131 Syntax --
3 ms (Default 2 ms value checked) Checkbox se- -lected User preference -Mode/Data Bits RTU (8)
RS-232C settings
32
35012293 11/2008
Modbus Slave
Target Machine (Slave) Driver Serial Inter- RS-232C face Flow Control Transmission Speed Slave Equipment Address Parity Bit Stop Bit None 19200 bps 1
Even 1 bit
Even 1 bit
Data Length 8 bit TX Wait Time Default value Equipment IEC61131 Syntax --
3 ms (Default 2 ms value checked) Checkbox se- -lected User preference -Mode/Data Bits RTU (8)
35012293 11/2008
33
Modbus Slave
34
35012293 11/2008
Modbus Slave
Driver Configuration
Overview To set up details about the information stored on the target machine, use the Driver Configuration dialog box. For an overview of the driver and protocol settings, see Environment Setup (see page 31). NOTE: For information on how to display the Driver Configuration dialog box, see the online help: Communications Setting Up Your Equipment Configuring Communication Settings. Screen example of Driver Configuration
Description
Area Manufacturer Driver Coils Description Displays the name of the equipment manufacturer. Displays the name of the driver. Defines the number of addresses in the target machine (slave). Coils can only be specified in multiples of 16. If the user does not specify a multipe of sixteen, the program will assign the closes multiple of 16. For example, if the user specifies 23, the program will assign 32.
35012293 11/2008
35
Modbus Slave
Description Defines the number of addresses in the target machine (slave). Discrete inputs can only be specified in multiples of 16. If the user does not specify a multipe of sixteen, the program will assign the closes multiple of 16. For example, if the user specifies 23, the program will assign 32. Defines the number of addresses in the target machine (slave). Defines the number of addresses in the target machine (slave). To define the transmit word order for 32 bit variables. (see page 27) Low byte first : to have the same behavior as XBT L1000 software. High byte first : to have the same behavior as Vijeo Designer V4.1 software. Inside PLCs a STRING is usually an array of words for which every word contains two characters (one character per byte). For example the HELLO! string representation is the following:
Input Registers Holding Registers Double Word word order ASCII Display byte order
If Low byte first option is selected the string displayed on the target machine screen is: HELLO!. If High byte first option is selected the string displayed on the target machine screen is: EHLL!O.
36
35012293 11/2008
Modbus Slave
Equipment Configuration
Overview You can connect multiple master controllers to the target machine. Use the Equipment Configuration dialog box to define the communication settings with each master controller.
WARNING
UNINTENDED EQUIPMENT OPERATION Do not use Modbus addresses 65, 126, or 127 if a gateways Modbus slaves will include a Schneider Electric Speed Variation device such as an Altistart soft-starter or an Altivar motor drive. The Altistart and Altivar devices reserve these addresses for other communications. Failure to follow these instructions can result in death, serious injury, or equipment damage. NOTE: For information on how to display the Equipment Configuration dialog box, see the online help: Communications Setting Up Your Equipment Adding a Device Driver.
35012293 11/2008
37
Modbus Slave
Description
Area COM Port Serial Interface Flow Control Transmission Speed Slave Equipment Address Parity Bit Stop Bit Data Length Description Defines which COM port to use on the target machine, for connecting to the equipment. Defines the serial connection for the selected COM Port: RS-232C or RS-485. Set to None, the driver handles flow control internally. Sets the communication speed in bits per second. This setting must match the equipment baud rate. Enter a value (1 to 247) to identify the target machine (slave). This setting must match the setting on the master controller. Sets a parity bit [Even or Odd] for use in detecting communication errors, or [None]. Defines the stop bit: 1 or 2 bits. Defines the length of each unit of data: 7 bit or 8 bit.
38
35012293 11/2008
Modbus Slave
Description Defines the number of milliseconds that the target machine waits, after receiving a communication packet, before sending a new request. Minimum TX Wait Time is at least 3.5 character time. Note: This parameter is automatically changed by the software to be consistent with the tranmission speed. However you could change it to increase its value manually. When selected, TX Wait Time is automatically updated to the transmission duration of 3.5 characters. When cleared, you will need to specify the TX Wait Time. When selected, IEC variable address syntax is used. (see page 26)
Default value
35012293 11/2008
39
Modbus Slave
Description
Area Maximum Connections Inactivity Timeout Description Defines the number of master controllers on the network. Defines the number of seconds a target machine waits before closing an inactive socket. Inactivity timeout is used in two conditions: Master controller tries connecting to a target machine and the number of sockets in use is at the Maximum Connections. If a socket has been inactive the for the time defined in the Inavitity Timeout, the socket is closed and made available for the new connection. A socket is inactive for 100 x Inactivity Timeout. The target machine closes this socket to make it available for a new connection. Slave Equipment Address IEC61131 Syntax (Addressing Mode) Not applicable. When selected, IEC variable address syntax is used. (see page 26)
40
35012293 11/2008
Modbus Slave
35012293 11/2008
41
Modbus Slave
Screen example 1 When the IEC61131 Syntax check box is cleared in the Equipment Configuration dialog box, address configuration is as follows.
Description
Area Address Offset (i) Description Choose the start address. Define the offset of the equipments discrete and word equipment types. Type the offset or use the [Address Selector] keypad to enter the offset:
42
35012293 11/2008
Modbus Slave
Description List the bit position (0-15) of the equipments discrete and word equipment types. Example: let's look at a register 40100 and assume the value of 5 is loaded: 40100 = 5 In binary, 40100 = 0000 0000 0000 0101 (16 bits) (assume Least Significant Bit, LSB is far right and this is j = 0.) So, 40001 + i, j where i = 99 and: j = 0 the bit is 1 j = 1 the bit is 0 j = 2 the bit is 1 j = 3 the bit is 0 j = 4 the bit is 0 and so on. Typing the offset or the bit allows you to preview the address immediately. Using the Address Selector updates the Preview after you click OK.
Preview
NOTE: Be careful when you send a string as table of word on Modbus (see page 27) because the LSB and MSB of each word are opposite in Premium and Quantum PLCs.
35012293 11/2008
43
Modbus Slave
Screen example 2 When the IEC61131 Syntax check box is selected in the Equipment Configuration dialog box, address configuration is as follows.
Description
Area Address Offset (i) Description Choose the address type (%M, %MW, %MD...). Define the offset of the equipments discrete and word equipment types. Type the offset or use the [Address Selector] keypad to enter the offset:
44
35012293 11/2008
Modbus Slave
Description List the bit position (0-15) of the equipments discrete and word equipment types. Example: let's look at a %MW10 the value of 5 is loaded: %MW10 =5 In binary, %MW10 = 0000 0000 0000 0101 (16-bits) (assume Least Significant Bit, LSB is far right and this is j = 0.) So, %MW10:Xj : j = 0 the bit is 1 j = 1 the bit is 0 j = 2 the bit is 1 j = 3 the bit is 0 j = 4 the bit is 0 and so on. Typing the offset or the bit allows you to preview the address immediately. Using the Address Selector updates the Preview after you click OK.
Preview
NOTE: Be careful when you send string as table of word on Modbus (see page 27) because the LSB and MSB of each word are opposite in Premium and Quantum PLCs.
35012293 11/2008
45
Modbus Slave
46
35012293 11/2008
Subject of this Chapter This chapter presents the Modbus RTU communication protocol used by the target machine and configurable using Vijeo Designer. What's in this Chapter? This chapter contains the following topics:
Topic General Operating Principle Example of a Serial Modbus RTU Communication Bus Page 48 51 54
35012293 11/2008
47
Modbus RTU
General
At a Glance Modbus RTU is a fieldbus used to communicate between devices of the same type according to a protocol originally defined by Modicon. Numerous proprietary or third-party devices can be used on this bus, which has become one of the industry standards. The communication protocol terminology defines the software (driver) installed in the devices that are connected to the Modbus RTU bus.
48
35012293 11/2008
Modbus RTU
Illustration The following illustration shows the position of the field buses in an industrial communication environment.
Architecture Example The following illustration shows a communication architecture, featuring a serial Modbus RTU bus.
35012293 11/2008
49
Modbus RTU
50
35012293 11/2008
Modbus RTU
Operating Principle
At a Glance Communication between same-type devices can only take place by defining interconnection standards that define the behavior of each device in relation to the others. These standards were developed by ISO (the International Standard Organization), which defined a standardized Network Architecture more commonly known as the OSI (Open System Interconnection) model. This model is made up of seven ranked layers that each perform a specific part of the functions necessary for interconnecting systems. The layers communicate with equivalent layers from other devices, via standardized protocols. Within a single device, layers communicate with their immediate neighbors via hardware or software interfaces. Layers of the OSI Model
NOTE: The Modbus RTU bus matches this model in terms of layers, without possessing all of them. Only the Application (Modbus), Network, Link and Physical (Modbus RTU) layers are necessary for this field bus.
35012293 11/2008
51
Modbus RTU
Application Layer The application layer of the RTU Modbus serial field bus is the one visible to the programs of the interconnected devices. This is used to formulate the requests (reading/writing words and bits, etc.) that will be sent to the remote device. The application layer used by the Modbus RTU bus is the Modbus application protocol. Example: a target machine connected to a Modbus RTU bus as master will send Modbus requests in order to update the graphic objects displayed on these pages. NOTE: For further details on the Modbus application protocol (request codes, class details, etc.), go to http://www.modbus.org. Link Layer The link layer of the serial Modbus RTU bus uses the master/slave communication principle. The principle of a link layer is to define a low-level communication method for the communication medium (physical layer). For the serial Modbus RTU bus, the master/slave method comprises polling slaves (interrogating each slave on the bus) via the master to find out if they have a message to send. When a slave has a message to send, it answers the master, which then gives it authorization to send its message. For each serial Modbus RTU bus, there must be a single master that controls the bus slaves. NOTE: One reason for master/slave management is that at any time it is possible to calculate transfer time for requests and the answers from each device. This therefore enables us to size the buses precisely, in order that there be no saturation or information loss. NOTE: When using the Modbus (RTU) driver, the target machine is the bus master. When using the Modbus Slave (RTU) driver, the target machine is a slave on the bus. NOTE: For further details (datagrams, frame sizes, etc.) go to http://www.modbus.org. Physical Layer The physical layer of the OSI model characterizes the topology of the communication bus or network, as well as the medium (cable, wire, fiber optic, etc.) that will transport the information and its electrical coding. Within the framework of a serial Modbus RTU bus, topology may be daisy-chained, derived or a mix of both. The medium is made up of shielded twisted pairs, and the signal is a base band signal with a default speed of 9600 bits per second, even parity, 8 data bits and 1 stop bit.
52
35012293 11/2008
Modbus RTU
NOTE: In order for all devices to be able to communicate among themselves on the same bus, the speed, parity and data bit number characteristics must be identical. For further details, refer to the documentation of the devices connected to the bus. Within the framework of target machines, this information is provided in the section on configuring the Modbus RTU driver.
35012293 11/2008
53
Modbus RTU
NOTE: When using Modbus (RTU) driver, the target machine is the bus master. When using Modbus Slave (RTU) driver, the target machine is a slave on the bus.
54
35012293 11/2008
Subject of this Chapter This chapter presents the Modbus TCP/IP communication protocol used by the target machines and configurable using Vijeo Designer. What's in this Chapter? This chapter contains the following topics:
Topic General Operating Principle Background on IP Addressing Example of a Ethernet TCP/IP Modbus Network Page 56 59 62 65
35012293 11/2008
55
Modbus TCP/IP
General
At a Glance Modbus TCP/IP is the combination of the Modbus application protocol with an Ethernet network (TCP, IP and Ethernet II or 802.3 layers). The advantage of such a combination is that it enables industrial devices to dialog using a standard computer communication support (standardization of hardware, reduced costs, transfer speed, integration on existing systems, etc.). The communication protocol terminology defines the software (driver) installed in the devices that are connected to the Ethernet TCP/IP network.
56
35012293 11/2008
Modbus TCP/IP
Illustration The following illustration shows the position of the Modbus TCP/IP network in an industrial communication environment.
Architecture Example The following figure shows a global communication architecture (Ethernet TCP/IP Modbus) and Modbus serial bus:
35012293 11/2008
57
Modbus TCP/IP
58
35012293 11/2008
Modbus TCP/IP
Operating Principle
At a Glance Communication between same-type devices can only take place by defining interconnection standards that define the behavior of each device in relation to the others. These standards were developed by ISO (the International Standard Organization), which defined a standardized Network Architecture more commonly known as the OSI (Open System Interconnection) model. This model is made up of seven ranked layers that each perform a specific part of the functions necessary for interconnecting systems. The layers communicate with equivalent layers from other devices, via standardized protocols. Within a single device, layers communicate with their immediate neighbors via hardware or software interfaces. Illustration The figure below describes the layers of the OSI model.
NOTE: The Ethernet Modbus TCP/IP network uses Application (Modbus), Transport (TCP), Network (IP), Link and Physical layers.
35012293 11/2008
59
Modbus TCP/IP
Application Layer The application layer used is the Modbus layer, i.e. the one visible by the programs of the interconnected devices. This is used to formulate the requests (reading/writing words and bits, etc.) that will be sent to the remote device. Example: a XBT G connected to an Ethernet network will send Modbus requests in order to update the graphic objects displayed on these pages. NOTE: For further details on the Modbus application protocol (request codes, class details, etc.), go to http://www.modbus.org. Transport Layer The transport layer is the TCP (Transport Control Protocol) layer. This provides information routing between two remote devices by managing end-to-end communication: Gateway switching, frame traffic management via routing tables, information disassembly/assembly when necessary, etc. This layer is standardized, and used on the Internet to relay information via several communication nodes. NOTE: For further details, consult the RFC 793 (Request For Change 793), go to http://www.faqs.org/rfcs/. Network Layer The network layer is the IP layer. This is used to define a single address for each device in an Ethernet network. This layer is standardized, and used on the Internet to define a single address for each connected device. NOTE: A brief reminder of IP addressing is given over the following pages (see page 62). Link Layer The link layer determines how frames circulate on the medium, and how the network stations communicate between themselves. It is made up of two sub-layers: the LLC (Logical Link Control) layer, complying with IEE 8802-2, and the MAC (Medium Access Control) layer, CSMA-CD (Carrier Sense Multiple Access, Collision Detection) method, complying with IEEE 8802-3. There follows a brief description of the link layer, explaining how this CSMA-CD access method works. Each station can send a frame when it wants, but where two stations emit a frame at the same time (or too close together for the recipient station to receive the message) there is a collision, and both frames are destroyed. However, the collision detection system enables each lost frame to be sent later.
60
35012293 11/2008
Modbus TCP/IP
With this method, we see that the more frames there are, the greater the risk of collision. However, this risk is compensated by the communication speed on the medium (physical layer). It is nevertheless recommended, as a means of providing optimal collision management, and a sufficiently fast data transfer that does not load the Ethernet networks more than 30%. For further details, refer to the Ethernet network documentation or training manuals. Physical Layer The physical layer of the OSI model characterizes the topology of the communication bus or network, as well as the medium (cable, wire, fiber optic, etc.) that will transport the information and its electrical coding. Within the framework of an Ethernet network, there may be a bus or derived topology. Currently, the most commonly-used connection solution is the 10 base T (RJ45 and twisted pair), but it is possible to use a fiber optic (10 Base F), thin coaxial (10 Base 2) or thick coaxial (10 Base 5), depending on the network transmission speed. The available transmission speeds are 10 MBits.s, 100 MBits/s or 1 GBits/s, depending on the selected hardware. . For further details, refer to the Ethernet network documentation or training manuals.
35012293 11/2008
61
Modbus TCP/IP
Background on IP Addressing
IP Address In an Ethernet TCP/IP network, each device must have a unique IP address. This address is made up of two identifiers, one for the network and the other for the connected machine. The uniqueness of the addresses is achieved as follows: When the network environment is of open type, address uniqueness is achieved by assigning a network identifier through the national authorized body of the country in which the network is located. When the network environment is of closed type, address uniqueness is managed by the companys network manager. An IP address is defined over 32 bits. It is made up of 4 numbers, one for each byte in the address. NOTE: IP addressing is standardized and widely circulated thanks to the Internet. A detailed description can be found in the RFCs (Requests For Comments, go to http://www.faqs.org/rfcs/) which stipulate the Internet standards and computer manuals that describe the networks. You can refer to these for further details. Example Depending on the size of the network, three classes of address can be used:
Class A is used for large-scale networks with a high number of connected sites.
62
35012293 11/2008
Modbus TCP/IP
Class B is used for medium-scale networks with fewer connected sites. Class C is used for small-scale networks with few connected sites. NOTE: Certain IP addresses, such as 127.0.0.1 or address 89.0.0.1 are reserved and cannot be used. For further details, refer to the corresponding RFC. Sub-Addressing and Sub-Network Masks An IP address is made up of two identifiers, one for the network and the other for the connected machine. In fact, the machine identifier can also include a sub-network identifier. In an open environment, having obtained a network identifier from the authorized body, the local system administrator is able to manage several networks. This makes it possible to set up local networks without making any changes for the outside world, which still has visibility over a single network designated by the network identifier. The sub-network mask shows the number of bits assigned respectively to the network identifier and the sub-network indicator (bits set to 1), then to the machine identifier (bits set to 0). Example Example: 140.186.90.3
This division allows 254 sub-networks to be created, with 254 machines per subnetwork. The chosen sub-network mask value must be consistent with the class of IP address. The sub-network mask value will be: for a class A address: 255.xxx.xxx.xxx, for a class B address: 255.255.xxx.xxx, for a class C address: 255.255.255.xxx, where the value xxx is chosen by the user.
35012293 11/2008
63
Modbus TCP/IP
Gateway The term Gateway is used in this manual in the sense of "router". If a recipient machine is not connected to the local network, a message will be sent to the "Default gateway" connected to the local network, which will send it either to another Gateway or to the end recipient.
64
35012293 11/2008
Modbus TCP/IP
35012293 11/2008
65
Modbus TCP/IP
66
35012293 11/2008
Appendix
4
Modbus function codes and exception error codes
Modbus function codes Table of Modbus function codes recognized by the target machine.
Classes Basic Base Regular Regular Regular Regular Supplementary services Supplementary services Supplementary services Supplementary services Function name Read Holding registers Write Multiple registers Read Coils Read Discrete Inputs Write Multiple Coils Diagnostic Read Input registers Write Single Coil Write Single register Read Device Identification (only for Modbus TC/IP with target machine server) Function code (hex) 03 10 01 02 0F 08 04 05 06 2B
NOTE: By default the target machine uses the function code 10 (FC 10) to write multiple registers. However, some devices do not know this function code. When a device doesnt know FC 10, the target machine will automatically use (without any error code) FC 06. In the same way, the target machine will use FC 05 instead of FC 0F. In addition, FC 06 and FC 05 will be used if Preferred Frame Length is set to Minimum possible. Modbus exception responses When a client device sends a request to a slave device it expects a normal response. One of four possible events can occur from the masters query:
67
35012293 11/2008
Appendix
If the slave receives the request without a communication error, and can handle the query normally, it returns a normal response. If the slave does not receive the request due to a communication error, no response is returned. The client program will eventually process a time-out condition for the request. If the slave receives the request, but detects a communication error (parity, LRC, CRC,...), no response is returned. The client program will eventually process a time-out condition for the request. If the slave receives the request without a communication error, but cannot handle it (for example, if the request is to read a nonexistent output or register), the server will return an exception response informing the client of the nature of the detected error. Table of Modbus Exception responses.
Code 01 Name Meaning
ILLEGAL FUNCTION The function code received in the query is not an allowable action for the server (or slave). This may be because the function code is only applicable to newer devices, and was not implemented in the unit selected. It could also indicate that the server (or slave) is in the wrong state to process a request of this type, for example because it is unconfigured and is being asked to return register values. ILLEGAL DATA ADDRESS The data address received in the query is not an allowable address for the server (or slave). More specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, a request with offset 96 and length 4 would succeed, a request with offset 96 and length 5 will generate exception 02.
02
03
ILLEGAL DATA VAL- A value contained in the query data field is not an allowUE able value for server (or slave). This indicates an improper data value in the structure of the remainder of a complex request, such as that the implied length is incorrect. It specifically does NOT mean that a data item submitted for storage in a register has a value outside the expectation of the application program, since the MODBUS protocol is unaware of the significance of any particular value of any particular register. SLAVE DEVICE FAILURE An unrecoverable error detected while the server (or slave) was attempting to perform the requested action.
04
68
35012293 11/2008
Appendix
Code 05
Name ACKNOWLEDGE
Meaning Specialized use in conjunction with programming commands. The server (or slave) has accepted the request and is processing it, but a long duration of time will be required to do so. This response is returned to prevent a time-out error from occurring in the client (or master). The client (or master) can next issue a Poll Program Complete message to determine if processing is completed. Specialized use in conjunction with programming commands. The server (or slave) is engaged in processing a longduration program command. The client (or master) should retransmit the message later when the server (or slave) is free. Specialized use in conjunction with function codes 20 and 21 and reference type 6, to indicate that the extended file area did not pass a consistency check. The server (or slave) attempted to read record file, but detected a parity error in the memory. The client (or master) can retry the request, but service may be required on the server (or slave) device. Specialized use in conjunction with gateways, indicates that the gateway was unable to allocate an internal communication path from the input port to the output port for processing the request. Usually means that the gateway is misconfigured or overloaded. Specialized use in conjunction with gateways, indicates that no response was obtained from the target device. Usually means that the device is not present on the network.
06
08
0A
0B
35012293 11/2008
69
Appendix
70
35012293 11/2008
Index
B C A
higher connection, 14 XBT GT1000/1005 series connection, 14 System structure, 12
C
cable connections, 17
I
IEC61131 Syntax, 39, 40 IP, 62 IP Addressing, 62
U
Unintended Equipment Operation, 26, 27, 37
W L
Loss of Control, 8 word order, 27
M
maximum consecutive addresses, 30 Modbus exception error codes, 67 Modbus function codes, 67
S
string word order, 28 System Ethernet connection, 24 system XBT G connection, 13 XBT GC 2000 series or higher connection, 15 XBT GK series, XBT GT2000 series or
35012293 11/2008
71
Index
72
35012293 11/2008