Driver For TCP-IP Communication With Devices Using Modbus Protocol
Driver For TCP-IP Communication With Devices Using Modbus Protocol
10
Doc. Revision AW March 5, 2014
Contents
INTRODUCTION ........................................................................................................................................................2
GENERAL INFORMATION ........................................................................................................................................3
DEVICE SPECIFICATIONS .........................................................................................................................................3
NETWORK SPECIFICATIONS.....................................................................................................................................3
DRIVER CHARACTERISTICS .....................................................................................................................................3
CONFORMANCE TESTING ........................................................................................................................................4
SELECTING THE DRIVER ........................................................................................................................................5
CONFIGURING THE DEVICE ...................................................................................................................................6
CONFIGURING THE DRIVER ...................................................................................................................................6
CONFIGURING THE COMMUNICATION SETTINGS .......................................................................................................6
CONFIGURING THE DRIVER WORKSHEETS ............................................................................................................ 10
CONFIGURING DRIVER SHEETS FOR COMMAND 23 (SIMULTANEOUS READ/WRITE OF HOLDING REGISTERS)................ 17
EXECUTING THE DRIVER ..................................................................................................................................... 20
TROUBLESHOOTING ............................................................................................................................................ 21
REVISION HISTORY............................................................................................................................................... 23
Page 1/24
Introduction
The MOTCP driver enables communication between the Studio system and devices using the Modbus protocol
over TCP/IP, according to the specifications discussed in this document.
This document will help you to select, configure and execute the MOTCP driver, and it is organized as follows:
General Information: Identifies all of the hardware and software components required to implement
communication between the Studio system and the target device.
Selecting the Driver: Explains how to select the MOTCP driver in the Studio system.
Configuring the Device: Describes how the target device must be configured to receive communication from
the MOTCP driver.
Configuring the Driver: Explains how to configure the MOTCP driver in the Studio system, including how to
associate database tags with device registers.
Executing the Driver: Explains how to execute the MOTCP driver during application runtime.
Troubleshooting: Lists the most common errors for this driver, their probable causes, and basic procedures
to resolve them.
Revision History: Provides a log of all changes made to the driver and this documentation.
Notes:
This document assumes that you have read the Development Environment chapter in Studios Technical
Reference Manual.
This document also assumes that you are familiar with the Microsoft Windows environment.
Page 2/24
General Information
This chapter identifies all of the hardware and software components required to implement communication
between the MOTCP driver in Studio and a target device using the Modbus protocol over TCP/IP.
The information is organized into the following sections:
Device Specifications
Network Specifications
Driver Characteristics
Conformance Testing
Device Specifications
To establish communication, your target device must meet the following specifications:
Manufacturer: Modicon or any device using the Modbus protocol communicating over TCP/IP
Compatible Equipment:
For a description of the device(s) used to test driver conformance, see Conformance Testing on the next page.
Network Specifications
To establish communication, your device network must meet the following specifications:
Device Communication Port: Modbus Ethernet Port
Driver Characteristics
The MOTCP driver package consists of the following files, which are automatically installed in the /DRV
subdirectory of Studio:
MOTCP.INI: Internal driver file. You must not modify this file.
MOTCP.MSG: Internal driver file containing error messages for each error code. You must not modify this
file.
MOTCP.PDF: This document, which provides detailed information about the MOTCP driver.
MOTCP.DLL: Compiled driver.
Page 3/24
You can use the MOTCP driver on the following operating systems:
Windows XP/7/8/2003/2008/2012
Windows CE
Windows Embedded
For a description of the operating systems used to test driver conformance, see Conformance Testing
below.
The MOTCP driver supports the following registers:
Register Type
Length
0x (Coil Status)
1 Bit
1x (Input Status)
1 Bit
3x (Input Register)
1 Word
4x (Holding Register)
1 Word
Write
Read
Bit
Integer
Float
DWord
BCD
BCD DW STRING
Conformance Testing
The following hardware/software was used for conformance testing:
Driver Configuration:
Driver
Version
10.5
Protocol: RTU
Cable: Ethernet Cable
Studio
Version
7.1
Operating
System
(development)
Operating
System
(runtime)
WinXP + SP3
Win7 x64
WinCEv5.00
Equipment
Wago 750-841 CPU
GE-FANUC 90-30 CPU-374
Schneider/Modicon TSX Quantum with NOE 211 00 module
Page 4/24
2. Select the MOTCP driver from the Available Drivers list, and then click the Select button.
Caution:
For safety reasons, you must take special precautions when installing any physical hardware. Please
consult the manufacturers documentation for specific instructions.
Page 5/24
Page 6/24
For safety reasons, you must take special precautions when connecting and configuring new
equipment. Please consult the manufacturers documentation for specific instructions.
Page 7/24
The communication settings and their possible values are described in the following table:
Parameters
Default Values
Valid Values
Signed or Unsigned
Value
Signed
Signed or
Unsigned
Invocation Identifier
-1 to 255
RTU
RTU
Swap:Block
Size:MaxGap
0:64:10
Description
ASCII
0 or 1 or 2
(Swap)
0 to 512
(Block Size)
0 to 512
(Max Gap)
Caution:
When you configure Legacy Swap in the Swap field of Communication Settings, the registers FPS,
FP3S, DWS, DW3S, BCDDW and BCDDW3S do Word Swap (not Byte Swap). This is in compliance
with the older versions of MODBU driver (v2.10 or older). The others registers are not swapped.
Note:
The device must be configured with exactly the same parameters that you configured in the MOTCP
Communication Parameters dialog.
Page 8/24
4. In the Communication Settings dialog, click the Advanced button to open the Advanced Settings dialog:
Page 9/24
Header
Body
Station field: Specify the IP Address of the device, using the following syntax:
<IP Address>:<Port Number>:<PLC ID>
Example 192.168.125.31:502:1
Where:
<Port Number> is the port number for the Modbus TCP protocol (usually 502); and
You can also specify an indirect tag (e.g. {station}), but the tag that is referenced must follow the
same syntax and contain a valid value.
Caution:
You must use a non-zero value in the Station field, and you cannot leave the field blank.
<Type> : Register type. Valid values are 0X, 1X, 3X, 4X, FP, FP3,DF,DF3,FP3S, DW, FPS, DWS,
DW3, DW3S, DWSW, BCD, BCD3, BCDDW, BCDDWS, BCDDW3, BCDDW3S, ID, ST and STS.
[Signed/Unsigned] (optional): Parameter used for integer values only. Valid values are S
(Signed) and U (Unsigned). If you do not specify this parameter, then Studio uses the default
parameter in the Communication Settings dialog.
[Bit] (optional): Use this parameter only for 3X (Input Register) and 4X (Holding Register)
types, to indicate which bit on the register will be read from and/or written to.
[StartByte] (optional): Use this parameter only for ST and STS, to indicate the initial byte.
You can also specify an indirect tag (e.g. {address}), but the tag that is referenced must follow the
same syntax and contain a valid value.
Caution:
This driver supports bit reading only; it cannot execute bit writing. Also, when an unsigned
DWord register type is specified, it can only be associated with a Real database tag in Studio.
Page 11/24
Header
Body
Page 12/24
Most of the fields on this worksheet are standard for all drivers; see the Communication chapter of the
Technical Reference Manual for more information on configuring these fields. However, the Station,
Header, and Address fields use syntax that is specific to the MOTCP driver.
3. Configure the Station and Header fields as follows:
Station field: Specify the IP Address of the device and the slot number, using the following syntax:
<IP Address>:<Port Number>:<PLC ID>
Example 192.168.125.31:502:1
Where:
<Port Number> is the port number for the Modbus TCP protocol (usually 502); and
You can also specify an indirect tag (e.g. {station}), but the tag that is referenced must follow the
same syntax and contain a valid value.
Caution:
Header field: Specify the address of the first register of a block of registers on the target device. The
addresses declared in the Body of the worksheet are simply offsets of this Header address. When
Read/Write operations are executed for the entire worksheet (see Read Trigger and Write Trigger
above), it scans the entire block of registers from the first address to the last.
The Header field uses the following syntax:
<Type>:<AddressReference>
Example 4X:10
Where:
<Type> is the register type (0X, 1X, 3X, 4X, FP,FP3,DF,DF3,FP3S,DW, FPS, DWS, DW3, DW3S,
DWSW, BCD, BCD3, BCDDW, BCDDWS, BCDDW3, BCDDW3S, ID, ST, STS, HRW).
After you edit the Header field, Studio checks the syntax to determine if it is valid. If the syntax is
invalid, then Studio automatically inserts a default value of 0X:0.
You can also specify a string tag (e.g. {header}), but the tag value that is referenced must follow the
same syntax and contain a valid value.
Page 13/24
The following table lists all of the data types and address ranges that are valid for the MOTCP driver:
Type
Syntax
Valid Range
Comments
0X
0X:0
varies by device
Coil Status: Read and write events using Modbus instructions 01, 05 and 15.
1X
1X:0
varies by device
3X
3X:0
varies by device
4X
4X:0
varies by device
Holding Register: Read and write events using Modbus instructions 03, 06
and 16.
FP
FP:0
varies by device
FPSW
FPSW:0
varies by device
FP3
FP3:0
varies by device
DF
DF:0
varies by device
DF3
DF3:0
Varies by device
FP3S
FP3S:0
varies by device
DW
DW:0
varies by device
32-bit Integer Value (Holding Register): Read and write 32-bit integer values
using two consecutive Holding Registers.
FPS
FPS:0
varies by device
DWS
DWS:0
varies by device
32-bit Integer Value (Holding Register): Read and write 32-bit integer values
using two consecutive Holding Registers with Byte Swap. (*)
DW3
DW3:0
varies by device
32-bit Integer Value (Input Register): Read 32-bit integer values using two
consecutive Input Registers.
DW3S
DW3S:0
varies by device
32-bit Integer Value (Input Register): Read 32-bit integer values using two
consecutive Input Registers with Byte Swap. (*)
DWSW
DWSW:0
Varies by device
32-bit Integer Value (Holding Register): Read and write 32-bit integer values
using two consecutive Holding Registers with Word Swap. (*)
BCD3
BCD3:0
varies by device
BCD Value (Input Register): Read events using Modbus instruction 04.
BCD
BCD:0
varies by device
BCD Value (Holding Register): Read and write events using Modbus
instructions 03, 06 and 16.
BCDDW
BCDDW:0
varies by device
BCD 32-bit Integer Value (Holding Register): Read and write 32-bit integer
values using two consecutive Holding Registers.
BCDDWS
BCDDWS:0
varies by device
BCD 32-bit Integer Value (Holding Register): Read and write 32-bit integer
values using two consecutive Holding Registers with Byte Swap. (*)
BCDDW3
BCDDW3:0
varies by device
BCD 32-bit Integer Value (Input Register): Read 32-bit integer values using
two consecutive Input Registers.
BCDDW3S
BCDDW3S:0
varies by device
BCD 32-bit Integer Value (Input Register): Read 32-bit integer values using
two consecutive Input Registers with Byte Swap. (*)
Page 14/24
Type
Syntax
Valid Range
Comments
ID
ID:0
varies by device
ST
ST:0
varies by device
String value (Holding Register): Reads and writes String values using
consecutive Holding Registers.
STS
STS:0
varies by device
String value (Holding Register): Reads and writes String values using
consecutive Holding Registers with Byte Swap.
HRW
HRW:0
varies by device
4. For each table row (i.e., each tag/register association), configure the Address field using the following
syntax
For all register types other than ST and STS use the following syntax:
[Signed/Unsigned]<AddressOffset>.[Bit]
Examples 10, S20, U40, 10.5
For ST and STS registers only, use the following syntax:
<AddressOffset>:<Length> or
<AddressOffset>.[StartByte]:<Length>
Example 10:5
Where:
[Signed/Unsigned] (optional): Parameter used for integer values only. Valid values are S (Signed)
and U (Unsigned). If you do not specify this parameter, then Studio uses the default parameter in the
Communication Settings dialog.
[Bit] (optional): Use this parameter only for 3X (Input Register) and 4X (Holding Register) types, to
indicate which bit on the register will be read from and/or written to.
[StartByte] (optional): Use this parameter only for ST and STS, to indicate the initial byte.
Cautions:
Use Bit Write commands in the Holding Register for the Write on Tag Change field only.
The Floating-point value is stored in two consecutive Holding Registers, where the address value
corresponds to the first Holding Register position. You must ensure that you do not configure a nonexistent address, or a conflict will occur.
The Floating-point values are 4 bytes using 6 significant digits.
Lastly, keep in mind that when using the Write Trigger feature, the driver writes to the entire block of
registers from the first address through the last. If there is a register that has not been declared in the
worksheet, and its address is within the block, then the register will receive a zero (0) value. Check the
worksheet for holes in the address range.
When an unsigned DWord register type is specified, it can only be associated with a Real database tag
in Studio.
Page 15/24
Writing bit values to the 4x registers is allowed, however there is no such function the Modbus
protocol. In this case, the driver performs the read-mask-write operation, Before writing, the driver first
reads the entire word, modify the bit that will be written and then writes back to PLC. Even with this
being a very fast operation, if in this period between reading and writing the PLC value changes, the
driver will overwrite it with the value that is being processed.
For examples of how device registers are specified using Header and Address, see the following table:
Device Register
Header
Address
00001
0x:1
00010
0x:0
10
01020
0x:1000
20
10001
1x:1
10010
1x:0
10
11020
1x:1000
20
30001
3x:1
30010
3x:0
10
31020
3x:1000
20
FP3:0
FP3S:0
1000
40001
4x:1
40010
4x:0
10
41020
4x:1000
20
40010 (bit 0)
4x:0
10.0
41010 (bit 7)
4x:1000
10.7
FP:1
FP:0
13
FP:1000
21
40000 to 40003
DF:0
30001 to 30004
DF3:1
FPS:1000
21
DW:1
DW:0
13
DW:1000
21
DWS:1
DW3:1000
21
DW3S:1
10
Page 16/24
Device Register
Header
Address
DWSW:1
BCD:1
BCD3:1000
21
BCDDW:1
BCDDWS:1000
10
BCDDW3:1
BCDDW3S:0
10
40001
ST:1:2
ST:1000:4
10
STS:1
0:2
STS:1000
10:20
For more information about the device registers and addressing, please consult the manufacturers
documentation.
Caution:
You must not configure a range of addresses greater than the maximum block size (data buffer length)
supported by the target device. The default block size is 64 bytes, but this can be changed in the
communication settings for the driver.
Page 17/24
5) Create another worksheet that will receive the read values, this worksheet should have the header
HRW:<first read address>, where first read address is the value specified in the Header field for the
worksheet created on step 1.
6) Associate all the addresses that you are reading with their respective tags, the picture below shows how
the worksheet would be configured considering the previous command worksheet example:
Page 18/24
The addresses in this worksheet can have a data type prefix. The following data types are supported:
Prefix
Data Type
B
Signed 8 bits variable (byte)
UB
Unsigned 8 bits variable (byte)
W
Signed 16 bits variable (word)
SW
Signed 16 bits variable (word) with byte swap
UW
Unsigned 16 bits variable (word)
USW
Unsigned 16 bits variable (word) with byte swap
DW
Signed 32 bits variable (double word)
SDW
Signed 32 bits variable (double word) with byte swap
UDW
Signed 32 bits variable (double word) with byte swap
USDW
Signed 32 bits variable (double word) with byte swap
UDW
Unsigned 32 bits variable (double word)
USDW
Unsigned 32 bits variable (double word) with byte swap
F
32 bits float points (float)
SF
32 bits float points with byte swap (float)
DF
64 bits float points (double)
SDF
64 bits float points with byte swap (double)
BCD
16 bits BCD value
BCDDW
32 bits BCD value
S
String (address should be S<register>.<Bytes>)
Page 19/24
If the Driver Runtime task is set to Manual, then select the task and click the Startup button to toggle the
tasks Startup mode to Automatic.
Page 20/24
Troubleshooting
If the MOTCP driver fails to communicate with the target device, then the database tag(s) that you configured for
the Read Status or Write Status fields of the Main Driver Sheet will receive an error code. Use this error code and the
following table to identify what kind of failure occurred.
Error Code Description
Possible Causes
Procedure to Solve
OK
None required
ILLEGAL
FUNCTION
CODE
ILLEGAL DATA
ADDRESS
ILLEGAL DATA
VALUE
SLAVE DEVICE
FAILURE
SLAVE DEVICE
BUSY
Negative Ack
Memory parity
error
10
Invalid Header
field
11
Invalid Address
field
Invalid Address
12
13
Checksum error
Protocol error
14
Generic TCP/IP
error
15
Invalid IP number
Wrong IP Address
Page 21/24
Possible Causes
Procedure to Solve
16
Connect error
18
19
20
100
Invalid Operation
1005
Timeout Error
-15
Timeout Start
Message
-17
Timeout between
rx char
Tip:
You can monitor communication status by establishing an event log in Studios Output window (LogWin
module). To establish a log for Field Read Commands, Field Write Commands and Protocol Analyzer, right-click in
the Output window and select the desired options from the pop-up menu.
You can also use the Remote LogWin module to establish an event log on a remote unit that runs on a
remote runtime, including Windows CE and Embedded
If you are unable to establish communication between Studio and the target device, then try instead to establish
communication using the devices own programming software (e.g., ModSoft). Quite often, communication is
interrupted by a hardware or cable problem or by a device configuration error. If you can successfully
communicate using the programming software, then recheck the drivers communication settings in Studio.
If you must contact us for technical support, please have the information generated by the command Support
Information in Studio's Help menu ready.
Page 22/24
Revision History
Doc.
Revision
Driver
Version
Author
Date
Description of changes
1.01
Sergio A. Poon
Nov/5/1999
1.02
Sergio A. Poon
Nov/9/1999
1.03
Sergio A. Poon
Apr/28/2000
1.04
Roberto V. Junior
May/4/2000
1.05
Roberto V. Junior
Jan/10/2001
1.06
Roberto V. Junior
Apr/3/2001
Enhanced performance
1.07
Loureno Teodoro
Jun/20/2001
1.08
Loureno Teodoro
Jul/23/2001
1.09
Loureno Teodoro
Aug/6/2001
1.09
Fabola Fantinato
Dec/5/2001
1.10
Luis F. Rodas
Dec/6/2001
1.11
Roberto V. Junior
Jan/8/2002
2.00
Eric Vigiani
Jun/27/2002
Modified driver algorithm to avoid Time-out errors due to the station number and
message size
2.01
Eric Vigiani
Jul/22/2002
2.02
Eric Vigiani
Aug/05/2002
2.03
Eric Vigiani
Aug/26/2002
Removed ASCII protocol type from the Communication Parameters dialog window
2.04
Eric Vigiani
Sep/30/2002
2.05
Fabio H.Y.Komura
Jan/07/2003
Included FP3 and FP3S Headers (Read Float Point to Input Register)
2.06
Eric Vigiani
Aug/22/2003
2.07
Eric Vigiani
Dec/18/2003
2.08
Loureno Teodoro
Mar/16/2004
Implemented disconnection after time out to avoid problems with devices that do not
accept multiple messages (the driver was not sending multiple messages; however,
the transport layer was doing it while the socket was open)
2.09
Eric Vigiani
May/25/2004
2.10
Jun/16/2004
2.11
Eric Vigiani
Jul/02/2004
2.12
Added support to BCD, BCD3, BCDDW, BCDDWS, BCDDW3 and BCDDW3S data
type.
2.13
Bruno A. Crepaldi
AA
2.14
Changed the Swap parameter to comply with old versions of the MODBU driver
(version 2.10 or older).
AB
2.15
Leandro Coeli
Nov/12/2004
Jan/18/2005
Page 23/24
2.16
Leandro Coeli
Feb/18/2005
AD
2.17
Leandro Coeli
Apr/26/2005
AE
2.18
Leandro Coeli
Jan/20/2006
AF
2.18
Michael D. Hayden
Jun/14/2006
AG
2.19
Graziane C. Forti
Aug/31/2006
Nov/10/2006
AH
2.20
Arthur S. Allievi
AI
2.21
Graziane C. Forti
Nov/23/2006
AJ
2.22
Plnio M. Santana
Jan/18/2007
AK
2.23
Plnio M. Santana
Jul/06/2007
AL
2.24
Plnio M. Santana
Jan/30/2008
AM
2.24
Plnio M. Santana
Apr/2/2008
AN
10.1
Marcelo Carvalho
Jan/07/2009
AO
10.1
Andre Bastos
Apr/10/2009
AP
10.3
Loureno Teodoro
Jul/1/2009
AQ
10.4
Andre Korbes
Sep/16/2010
AR
10.5
Paulo Balbino
Jan/17/2013
AS
10.6
Paulo Balbino
Aug/15/2013
AT
10.7
Charan Manjunath
P
Oct/21/2013
Updated Error Codes table with Error Code 1 and removed Error Code 17
AU
10.8
Charan Manjunath
P
Nov/01/2013
Updated with FPSW in the list of data types and address ranges
AV
10.9
Priya Yennam
Jan/20/2014
AW
10.10
Charan Manjunath
P
Mar/5/2014
Page 24/24