One of the most requested network protocols other than Ethernet/IP is communication using Modbus Transmission Control Protocol (TCP). Since Logix controllers don’t natively support TCP, usually an additional hardware module or gateway from a Rockwell Encompass partner is used. If the application requires communication to many devices and is planned for during the hardware selection phase, a partner product is a great way to go and should be planned into the project. But what if it doesn’t require extensive communication and extra hardware was overlooked?
Here’s a simple way of doing Modbus TCP communication in a Logix controller without additional hardware. There is code available on the Rockwell sample code website to serve that purpose. Simply go to the sample code website and search for Modbus TCP. Download from there and unzip the downloaded file. It is broken down by Client code or Server code.
There are a few things to consider before you decide to use this in place of a hardware-based solution. The code uses a considerable amount of controller memory. For the first client instance about 93 KB of controller memory is used. Each additional instance uses 20 KB. The server instance uses 123 KB of memory and only one can be used per Ethernet port. The smallest CompactLogix controller only has 384 KB keep that in mind for the smaller memory controllers.
Each use of the client AOI talks to one Modbus TCP device. The client AOI allows for the configuration of five reads or writes to the node. The main thing to consider is if the application goes past one or two AOI instances you should probably consider a hardware solution.
Once downloaded and unzipped you will see two L5X import files, one for client and one for server. The main thing to remember is to use the rung import feature in Studio 5000 each time you add to your program. Do not copy and paste, this won’t work. You can change the AOI tag names during the import if desired.
There are also manuals included for each function which details the import process and how to change tag names. If you are unfamiliar with Modbus commands and addressing, the manual offers a brief description of the bit and word level commands available, along with address ranges for each.
Once you have finished importing the rung into your project the communication parameters can be configured. This is done by going to the tag monitor tab and entering the appropriate values in required and optional locations. Keep in mind since they are contained as tag values, you should be saving the program anytime you make a change. The manual details what needs to be entered for the AOI to function correctly depending on which processor is being used.
The actual data transactions also need to be configured for specific data tables being read or written to. Up to five can be used per client instance.
Below is data required for each transaction:
There is a common tag data table created with the first import that is used with subsequent instances. It has tags for the different data type that can be read and written so if multiple clients are connected the user must keep track of what client is using which data area. This tag contains four separate data areas for coils (0xxxx), discrete inputs (1xxxx), input registers (3xxxx) and holding registers (4xxxx). These tag values can be read and populated by the user application without any restrictions.
There are also status bits available to monitor and alert operators if there is a communication failure.
The use of these sample AOIs for Modbus TCP communication is not intended for every application. Most cases would be better served, and more robust, with the use of a hardware solution. Several Encompass partners offer solutions so please discuss your requirements with a Rumsey specialist to make sure the best option is selected for your specific application. If you do find yourself on a startup and a last-minute request to communicate with a Modbus TCP system or device pops up, the sample code discussed may just be the ticket to get you out of a jam. It’s free code, so download it to get familiar before you need to use it.