Вы находитесь на странице: 1из 7

Modbus Slave EZ Quick Start

Introduction This document is a companion to the Logix Modbus Slave EZ code (ModbusSlaveEZ_V2_0_1.ACD). It is currently uses a L23 processor but will work with any Logix processor. This is proven code (has been in use since February 2004) that has been only been slightly modified to make it easier to use. The original code is still available as a download from the Sample Code website (Download Using any Logix processor as either a Modbus RTU master or slave and use the ModbusSlave_V2_0.ACD file). In addition to the modifications, this Quick Start will walk you through the process of getting your Modbus network up and running. The document has four parts. Summary: An overview of what the code does for quick understanding. Getting Started: Using the code with your project. Intro to Modbus: Just what you need to know about Modbus to use the code. Example System: The code was tested with a MicroLogix1100 acting as a Modbus Master. The MicroLogix1100 code is included along with a description of how to set it up and make it work. For more detailed information, see the Application Solution document Using Logix5000 Controllers as Maters or Slaves Pub No. CIG-AP129A-EN-P. It is available with the download of the original code described above or from the Literature Library.

Summary Once you have a viable Modbus Master and communications link to the Logix processor, and you download the Logix Modbus EZ code to the processor, you should be able to communicate successfully by setting only two tags in the Modbus Slave Logix processor:

Modbus_A_Enable simply enables the Modbus code (enabled/on by default), Modbus_B_Slave_Node_Address is where you set the Slave address. The Modbus Master will either read data from or write data to the Modbus Slave Logix processor. No program code is required in the Modbus Slave Logix processor for this to occur all communications activity is performed by the Master. The data locations (as defined by Modbus) are supported by four tags. Binary Data Modbus_Data_Coils_0xxxx Modbus_Data_Contacts_1xxxx Integer Data Modbus_Data_Holding_Registers_4xxxx Modbus_Data_Input_Registers_3xxxx The Master can either read data from or write data to these tags. The tags size is set to a default size of 250 words. This should cover most applications (the maximum Modbus request supported is 120 words, but this size will allow for offsets into the tag).

Getting Started A Main Program folder with a Ladder Logic Main Routine is provided as a convenience as a starting point for your application.

You can use modify this as you wish for your application. Simply copy and paste your Controller Tags, Routines, Program tags, and Tasks into the Modbus project. Then Verify and download. The Modbus_Slave_Code folder contains the Modbus code. There is no need to interact with anything in this folder. Do not modify any programs or tags within this folder.

Intro to Modbus Modbus is a serial (often RS-232) protocol that has been used for many years to set up multidrop wide area networks for SCADA (Supervisory Control and Data Acquisition) applications. Two of the most common applications are Water/Wastewater systems and Oil/Gas Pipelines. They both require communications to PLCs over a wide geographical area. The communications media has traditionally been via either phone modems or radio modems connected via the RS232 ports on the PLC. Modbus uses a Master/Slave communications scheme as follows:

One node (typically a PC or a PLC) is designated as Master and the others on the network are Slaves. The network shown could be phone or radio, but in either case it is multidrop/broadcast in nature. When any node sends a message, all others can hear it. This is why one node is the Master and initiates all communications. When the Master initiates a read or write message, all the Slaves can hear it, but only the Slave addressed in the Masters message responds. Thus, even though all nodes are tied together via a phone line or a common radio frequency, only one will talk at a time.

A subset of the above network example is a simple case where you have just a Master and single Slave connected via a single point to point link. This scenario is often to connect PLCs locally (no modems required) to other devices that support Modbus.

Note that the PLC could alternatively be the Modbus Master talking to some other device that is a Modbus slave. Now that we have discussed the network topology, lets take a look at how the data is transmitted. Modbus allows the Master to read or write data from the Slaves. The following commands are available for use by the Master: Messages to Read/Write Binary Data Read Coils (Function Code 01) from memory locations 0xxxxx Read Discrete Inputs (Function Code 02) from memory locations 1xxxxx Write Single Coil (Function Code 05) to memory locations 0xxxxx Write Multiple Coils (Function Code 15) to memory locations 0xxxxx Messages to Read/Write Integer Data Read Holding Registers (Function Code 03) from memory locations 4xxxxx Read Input Registers (Function Code 04) from memory locations 3xxxxx Write Single Register (Function Code 06) to memory locations 4xxxxx Write Multiple Registers (Function Code 16) to memory locations 4xxxxx There are two versions of Modbus: RTU and ASCII. RTU is the most efficient and most widely used for SCADA applications and is the one used here.

Example System Modbus Test System Code is provided to help get your system up and running. To use the system you will need: A Logix processor with an EtherNet port. A MicroLogix 1100 processor. A 1761-CBL-PM02 MicroLogix programming cable. The code you will use is: The ModbusSlaveEZ_V2_0_1.ACD project file for the Logix processor. The ML1100 Modbus Master Test.RSS project file for the ML1100 processor. The MicroLogix1100 processor will act as a Modbus Master to the Logix processor Modbus Slave. Plug one end of the PM02 into the ML1100 serial port and the other into the Logix processor serial port. Download the code into the respective processors using their Ethernet ports.

The ML1100 program has the following MSG instruction

You can toggle the B3:0/0 bit to trigger the MSG. It sends a 100 word Read Holding Register command to the Logix Modbus Slave at Modbus Slave address 10 (the default in the Logix program). The data is read starting at the Logix tag Modbus_Data_Input_Registers_3xxxxx[99]. The reply is placed starting at N7:0 of the ML1100.

Вам также может понравиться