Modbus Protocol User Guide Part Number 900-271 Revision F October 2005
Copyright & Trademark © 2005, Lantronix. All rights reserved. No part of the contents of this book may be transmitted or reproduced in any form or by any means without the written permission of Lantronix. Printed in the United States of America. Ethernet is a trademark of XEROX Corporation. UNIX is a registered trademark of The Open Group. Windows 95, Windows 98, Windows 2000, and Windows NT are trademarks of Microsoft Corp. Netscape is a trademark of Netscape Communications Corporation.
Contents Figures 4 Tables 4 1: Introduction 5 Modbus ___________________________________________________________ 5 Extended Modbus System Example _____________________________________ 6 Modbus/TCP Master Talking to Modbus/TCP Slave _____________________________ 6 Modbus/TCP Master Talking to Modbus/RTU Serial Slave ________________________ 7 Modbus/RTU Serial Master Talking to Modbus/TCP Slave ________________________ 7 Modbus/RTU Serial Master Talking to Modbus/RTU Serial Slave ___________________ 7
Contents Delay after CTS Going Active (0-1275 ms, 5ms increments) ______________________ 13 Delay Dropping RTS after Transmitting (0-1275 ms, 5 ms increments) ______________ 13 Advanced Modbus Protocol Settings____________________________________ 13 Slave Address (0 for auto, or 1…255 fixed otherwise) ___________________________ 13 Allow Modbus Broadcasts (1=Yes 2=No) _____________________________________ 13 Use MB/TCP 0x0B/0x0A Exception Responses (1=No 2=Yes) ____________________ 14 Disable Modbus/TCP p
1: Introduction This protocol manual is for use with Lantronix Industrial Automation Protocol (IAP) Device Servers, such as the XPress DR-IAP, CoBox-FL-IAP, UDS100-IAP and UDS10-IAP. In addition to our IAP Device Servers, the Modbus protocol is supported on various embedded products including versions of the XPort, WiPort, and Micro. The default protocol in new IAP Device Servers is the Standard Tunneling protocol, a serial protocol used to connect thousands of intelligent devices to the Ethernet.
1: Introduction Extended Modbus System Example Figure 1-1. Extended Modbus System Example Figure 1-1 shows four specific styles of Modbus operations. Modbus/RTU devices are traditionally split into two groups. (CoBox Modbus refers to an IAP Device Server.) Modbus slave devices generally are the workhorse devices. They perform their tasks 24 hours a day, 365 days a year, for example, tasks such as flow metering, temperature control, batch loading, or even running entire automated assembly lines.
1: Introduction It is revolutionary for such a simple and flexible protocol as Modbus to offer such functionality. Therefore, Modbus/TCP offers exciting new design options for industrial users, which the Lantronix IAP Device Servers extend to traditional Modbus/RTU serial devices. Modbus/TCP Master Talking to Modbus/RTU Serial Slave Devices D, G, and H are traditional Modbus/RTU slave devices. Device D uses a point-to-point electrical interface like RS232.
2: Configuring Modbus Network Protocols The IAP Device Server uses TCP/IP protocols for network communication. The supported standards are ARP, UDP, TCP, ICMP, Telnet, TFTP, DHCP, and SNMP. For transparent connections, TCP/IP (binary stream) or Telnet protocols are used. Firmware upgrades can be made with the TFTP protocol. The IP protocol defines addressing, routing, and data block handling over the network.
2: Configuring Modbus Configuration Methods The IAP Device Server can be configured using remote or local methods. Either use an ASCII terminal or a terminal emulation program to locally access the serial port, or use a Telnet connection to port 9999 to configure the unit over the network. See the Getting Started chapter of the User Guide for your IAP Device Server. The IAP Device Server configuration is stored in nonvolatile memory and is retained without power. The configuration can be changed any time.
2: Configuring Modbus To save the configuration and exit, type S on the command line and press Enter. This saves the parameters to EEPROM. Caution: DO NOT POWER CYCLE the unit too fast after doing this. Allow the unit to reboot naturally one time first. To quit without saving, type Q on the command line and press Enter. The unit reboots. To restore the default values, type R on the command line and press Enter. Figure 2-1.
2: Configuring Modbus Network/IP Settings Select 1 to configure the Device Server’s network parameters. The following values can be set or changed. To understand and select the appropriate values, consult one of the many TCP/IP books available today and your network administrator. IP Address The IP address must be set to a unique value on your network. If you are not familiar with IP addressing on your network, please consult your network administrator.
2: Configuring Modbus Serial Protocol (1=Modbus/RTU, 2=Modbus/ASCII) Serial Modbus comes in two forms. Modbus/RTU uses 8-bit data bytes to send binary information. However, some devices cannot handle 8-bit data bytes, so Modbus/ASCII is used. Modbus/ASCII is a slower protocol, where each 8-bit data byte is converted to 2 ASCII characters. Since the IAP Device Server converts both to and from Modbus/TCP fully, you can mix any combination of RTU and ASCII devices on a Modbus/TCP network.
2: Configuring Modbus Delay after Output of RTS (0-1275 ms, 5ms increments) Only asked if RTS/CTS mode is variable. After the IAP Device Server asserts the RTS/CTS signal, it delays from 0 to 1275 ms before continuing. Normally this is set to 0. Only set a value here if your device, modem, or cable is non-standard. Wait for CTS to Go Active (N/Y) Only asked if RTS/CTS mode is variable. Answering N causes the IAP Device Server to ignore the RTS/CTS response from the modem.
2: Configuring Modbus Modbus broadcast from a serial master device is discarded regardless of this parameter setting. Use MB/TCP 0x0B/0x0A Exception Responses (1=No 2=Yes) Traditional serial Modbus uses silence to signal some errors. While this works well with direct serial lines, it causes serious problems on a TCP/IP wide-area-network where delays are not so predictable. See for a full discussion.
2: Configuring Modbus Character Timeout (10-7050 msec) This sets the timeout between characters received. Official Modbus/RTU defines a 3.5 character time-out, but complex devices have various interrupts that can cause 5 to 10 character “pauses” during transmission. A safe value for general use with Modbus is 50 msec. Note: Setting this value lower than 50 msec will not improve performance and may even make performance worse.
2: Configuring Modbus Unit ID to IP Address Lookup Table Figure 2-2. Unit ID to IP Address Lookup Table These parameters only apply when Modbus Master is selected for the Serial Protocol. The new menu appears like this: 1) Network/IP Settings: IP Address . . . . . . . . . . 192.168.100.77 Default Gateway . . . . . . . --- not set --Netmask . . . . . . . . . . . --- not set --2) Serial & Mode Settings: Protocol . . . . . . . . . . . Modbus/RTU,Master(s) attached Serial Interface . . . . . . .
2: Configuring Modbus Otherwise enter values 3 to 60 to automatically close the last socket after 3 to 60 seconds of idle time. Redundant Entry Retries after (15-60 sec. 0=disable feature) Enter the time in seconds for redundant entry retries or set to 0 to disable the feature. A)dd, D)elete, E)xit Select Function You can either add or delete entries in the IP address table. They are automatically sorted into increasing order. Enter E when you are satisfied with the table to return to the main menu.
3: Monitor Mode and Firmware Upgrade The easiest way to upgrade your protocol firmware (or “reflash”) is to use the DeviceInstaller utility that is on your software CD-ROM. You can also download DeviceInstaller from the Lantronix web page. The User Guide for the Device Server explains two other ways to reflash. You can do it serially with HyperTerminal or directly by Ethernet with a Trivial-File-TransferProtocol (or TFTP) Client.
4: WiPort and WiBox Implementation The Modbus master/slave functionality on the WiPort and WiBox is similar to the Modbus implementation on other platforms such as the UDS-10 or XPress-DR. The difference is the configurable pins on the WiPort (CP0-CP10) and the WiFi settings on the WiPort and WiBox are configurable from the Setup Menu. The WiPort and WiBox have 2 serial ports.
4: WiPort and WiBox Implementation Defaults is an input read at startup that tells the firmware to reset configuration to factory defaults. After assigning the applicable function by pressing Enter, you are then asked if the pin is inverted (active low). CP0 Function (hit space to toggle) GPIO (In) Invert (active low) (Y) ? A function should be assigned to each configurable pin. GPIO (Input) should be the default for all unused or unassigned pins.
4: WiPort and WiBox Implementation parameters are used to direct Read Coil Status, Read Input Status, Force Single Coil and Force Multiple Coils Modbus commands to the WiPort’s GPIO. Other commands or unmatched addressing are directed to the serial port. Local slave address for GPIO (0 to disable, or 1..255) (0) ? 3 Starting offset (0x/1x0001..
5: XPort Implementation The Modbus Master/Slave functionality on the XPort is similar to the Modbus implementation on other platforms (such as the UDS-10 or XPress-DR). A notable difference is the configurable pins on the XPort (CP1-3) are configurable from the setup menu. The menu option for Modem Control Settings has been replaced with Modem/Configurable Pin Settings on the XPort.
6: Troubleshooting and Technical Support Using the IAP Device Server firmware is normally easy. However, if a problem occurs, it is difficult to troubleshoot without an in-depth knowledge of Modbus and the system dynamics of polling. Some general guidelines for troubleshooting: Start polling slowly and increase speed gradually. Cabling is the most common problem with device networking. If you have created a custom cable, make sure your pinout is correct.
6: Troubleshooting and Technical Support Table 6-1. Baud Rate Baud Rate Byte/Sec Bit Time (msec) Byte Time (msec) 256 Byte Time (msec) (in sec) 300 30 3.333333 33.333333 8533.333333 8.53 600 60 1.666667 16.666667 4266.666667 4.27 1200 120 0.833333 8.333333 2133.333333 2.13 2400 240 0.416667 4.166667 1066.666667 1.07 4800 480 0.208333 2.083333 533.333333 0.53 9600 960 0.104167 1.041667 266.666667 0.27 19200 1920 0.052083 0.520833 133.333333 0.
6: Troubleshooting and Technical Support Delays f and h are defined by the baud rate. Assuming an 8 bytes poll and 255byte response, at 9600 baud this is at least 275 msec, while at 1200 baud, this is at least 2200 msec (2.2 sec). Delay g is defined by the device. Oddly enough, the simpler the device, the faster it tends to reply. Some controllers only allocate fixed time slices to process a response from shared memory – for example once each 100 msec.
6: Troubleshooting and Technical Support After a while, the IAP Device Server seems to take longer and longer to answer – after a few hours, it takes 10 minutes or more for systems changes to propagate up to the master/client. All these relate to the same issue – a mismatch in queuing behavior and expectation by the master/client to the new realities of Ethernet. (It is not the IAP Device Server behaving poorly.
6: Troubleshooting and Technical Support Device Server can only process on average 290 of those per minute and some carry over. After 10 minutes, you may have up to 100 “stale” responses waiting in your master’s TCP buffer. This makes it appear as though there is now a 20second “lag” in data reaching the master. Here is the source of your “data taking longer and longer to propagate to Master/Client” problem.
6: Troubleshooting and Technical Support Technical Support If you are experiencing an error that is not described in this user guide, or if you are unable to fix the error, you may: Check our online knowledge base at http://www.lantronix.com/support. Contact Technical Support in the US: Phone: 800-422-7044 (US only) or 949-453-7198 Fax: 949-450-7226 Our phone lines are open from 6:00AM - 5:30 PM Pacific Time Monday through Friday, excluding holidays.