PLC

Rockwell CompactLogix PLC as Modbus TCP Server: A Quick Tutorial

Learn how to set up a Rockwell CompactLogix PLC as a Modbus TCP server, configure communication, and test data polling for seamless automation.

Agustin Pelaez
· 12 min read
Send by email

In the ever-evolving world of industrial automation, seamless communication between devices is a cornerstone of efficiency and productivity. For engineers and technicians, ensuring that controllers, sensors, and systems can "talk" to each other without barriers is vital. This is where Modbus TCP, a widely adopted industrial communication protocol, proves indispensable.

Allen-Bradley ControlLogix PLCs, renowned for their reliability and performance, take this capability to the next level. As part of Rockwell Automation’s flagship lineup, ControlLogix PLCs offer unparalleled processing power, scalability, and flexibility. Combined with Modbus TCP, they provide a robust solution for integrating data across diverse systems and devices.

This quick tutorial not only guides you through setting up a Rockwell ControlLogix PLC as a Modbus TCP server but also delves into the broader benefits of Allen-Bradley PLCs and the key advantages of Modbus TCP in industrial environments. Whether you're a seasoned automation professional or exploring these technologies for the first time, this blog provides the insights and steps you need to streamline your operations with ease.

Why Choose an Allen-Bradley CompactLogix PLC?

Allen-Bradley CompactLogix PLCs are a go-to solution for industrial automation, offering a perfect balance of performance, scalability, and cost-effectiveness. Backed by Rockwell Automation’s century-long legacy, the CompactLogix family delivers dependable control solutions for a wide range of applications.

CompactLogix PLCs shine in medium-sized systems and distributed control setups, where efficiency and adaptability are key. With robust processing power and versatile connectivity, they excel in handling complex automation tasks while maintaining ease of use. Accessing and managing information directly from at the machine level is crucial in industrial automation, and CompactLogix PLCs provide the necessary real-time actions, metrics, and visualizations to achieve this.

CompactLogix PLCs leverage Studio 5000, a powerful yet user-friendly software. This tool allows users to program the PLCs using a variety of languages, such as ladder logic, structured text, and function block diagrams, enabling faster development and deployment.

Here’s why CompactLogix PLCs are a trusted choice:

  • Performance: CompactLogix PLCs provide reliable control with fast processing speeds, ensuring efficient operation even in demanding applications.
  • Scalability: Ideal for systems that need room to grow, CompactLogix PLCs support expansion with additional modules and devices, making them suitable for dynamic industrial environments.
  • Versatility: These PLCs support multiple communication protocols, allowing seamless integration with diverse industrial systems for easier data collection.
  • Cost-Effectiveness: CompactLogix PLCs deliver high performance at a lower cost compared to larger systems like ControlLogix, making them a practical choice for mid-range automation projects.
  • Durability: Designed for industrial use, CompactLogix PLCs are built to withstand harsh conditions, ensuring minimal downtime and long-term reliability.

For businesses seeking a flexible, affordable, and high-performing control solution, Allen-Bradley CompactLogix PLCs provide an unmatched combination of features and reliability. Their ability to adapt to evolving industrial needs makes them a valuable asset in achieving operational excellence.

Types of Allen-Bradley PLCs

Allen-Bradley PLCs, developed by Rockwell Automation, cater to diverse industrial automation needs. From compact units for small-scale operations to advanced systems for complex processes, the range ensures there’s a controller tailored to every application. Early models of PLCs lacked advanced analytics and data structures, but modern models now include these features, enhancing their capabilities and efficiency.

MicroLogix

The MicroLogix series is compact, budget-friendly, and ideal for small-scale automation tasks. These controllers offer dependable performance and robust programming capabilities, making them a practical choice for businesses seeking cost-effective solutions for straightforward automation requirements. They also gather data from various devices and protocols, which is crucial for efficient data management and advanced analytics in small-scale automation.

CompactLogix

As a mid-range option, CompactLogix PLCs strike the perfect balance between performance and scalability. They are well-suited for medium-complexity systems, where selecting and defining relevant PLC variables is crucial for effective data collection and monitoring. They can handle larger tasks compared to the MicroLogix series.

ControlLogix

ControlLogix PLCs are the flagship series, designed for large-scale and highly complex automation systems. These controllers deliver exceptional processing power, modularity, and flexibility. With features like seamless integration, real-time communication, and advanced security functions, ControlLogix PLCs are the gold standard for demanding applications.

PLC-5

The PLC-5 series is a legacy line that was renowned for its reliability and rugged design. Though no longer a preferred choice for new installations, many manufacturing facilities still rely on PLC-5 controllers for critical operations, particularly in systems using Data Highway Plus communication.

SLC 500

Another legacy series, the SLC 500 controllers were mid-range solutions before CompactLogix emerged. Known for their durability and simplicity, SLC 500 PLCs played a significant role in industrial automation during their prime. While newer models have taken their place, they remain a valuable machine in many established systems.

Allen-Bradley’s wide range of PLCs ensures a solution for every need, from legacy systems that have stood the test of time to cutting-edge controllers driving the future of industrial automation.

Model

Best For

Connectivity

Scalability

Comments

MicroLogix

Small-scale automation tasks

Basic Ethernet, RS-232

Low

Compact and cost-effective for simple tasks.

CompactLogix

Medium-complexity systems

EtherNet/IP, Modbus TCP

Moderate

Ideal for growing operations needing flexibility.

ControlLogix

Large-scale, complex systems

EtherNet/IP, Modbus TCP

High

Industry-leading performance and modularity.

PLC-5

Legacy systems

Data Highway Plus

Limited

Still in use but phased out for newer systems.

SLC 500

Legacy mid-range systems

Ethernet, RS-485

Limited

Durable, but mostly replaced by modern models.

Requirements

Hardware Requirements

  1. Allen-Bradley CompactLogix 5380 series.

Note: The CompactLogix 5380 series does not natively support Modbus TCP or RTU. For this reason, an Add-On Instruction (AOI) is used to implement Modbus TCP. If you use any other model that natively supports Modbus, you can skip this step.

  1. Profinet/Ethernet cable

Software Requirements

  1. Studio 5000 ( you can use the trial software downloaded from this link)
  2. Modbus TCP Add-On Instructions v2.04
  3. ModbusClientX ( you can use the software downloaded from this link)

Step-by-step Guide

Step 1: Creating the Project in Studio 5000

1. Open Studio 5000 and click on ‘New Project’. In the new window, select ‘Logix’ in the left pane and then select ‘5069-L320ER CompactLogix 5380 Controller’.

  1. Complete the configuration according to your project's characteristics.

Step 2: Download AOI and Configure the Task

  1. Access this Rockwell link and download the file called ‘Modbus TCP Add-On instructions for ControlLogix and CompactLogix controllers, AOI Version 2.04.00’.

2. Back in Studio 5000, right click on ‘Tasks’ ⟶ ‘New Task’. Name the task, ensure its ‘type’ is periodic, and define the period to 20 ms. Rockwell recommends the rate to be 10ms or higher (slower rates will reduce controller load and reduce performance, while faster rates will increase performance but will add a significant load to the controller).

3. Create a program within the new task. Do it by right clicking on the task ⟶ ‘Add’ ⟶ ‘New Program’. Name it.

4. Now we will create a new routine within this new program. Do this by right clicking on the program ⟶ ‘Add’ ⟶ ‘New Routine’. Name it and in the “in program or phase” option, set it as “MainProgram”.

5. Then create another routine (which we called TCPServer). Name it and in the “in program or phase” option, set it as “ModbusTCPProgram”.

6. Open your main routine (called “TCPMain” in our case) and, within it, call the other routine (“TCPServer”) by clicking on the question mark and selecting your other routine in the drop-down menu.

(This image is not from this particular project, but illustrates the process).

Note: Even though you can create everything in one routine, it's better practice to split it up across multiple routines.

  1. Open the secondary routine (“TCPServer” in our case), right click on the ladder and select the “import rungs” option. A pop-up will appear, look for the folder where you downloaded the AOI (within the ‘Logic’ file), select the ‘raC_Opr_NetModbusTCPServer_Rung.L5X’ file. The Modbus TCP AOI will be added into the routine.

After successfully importing the AOI, the program window should look like this:

Note: To know details about the implementation of the AOI, you are highly recommended to read the documentation available in the downloaded ZIP file.

Step 3: Download The Program to the PLC

  1. Now the final step is to download the project into the PLC. Head towards the ‘Communication’ tab. Select ‘Who Active’. We will download the program with all the default settings, except for “Inp_Enable”, which we set to 1.
  2. A new window will pop up for RSLinx. Expand the “AB_ETHIP-1, Ethernet” option, look for your PLC in the list, select it and click on “download”.

You should see the connection reference status “sts_waiting”.

  1. Now, right click on “Ref_ModbusData” and select “Monitor Server_01_Data”. That should take you to a window like the one below:

4. In this window, expand the holding registers and input any random values there.

This is the value that should be displayed when you poll the corresponding register using any Modbus client. We will test this in the next section of the post.

Step 4: Test Modbus Communication With ModbusClientX

To verify that the PLC is functioning correctly as a Modbus TCP server, we use the ModbusClientX tool to poll the PLC for Modbus data.

  1. Open ModbusClientX and select Modbus TCP.
  2. Enter your PLC’s IP address and click on “connect”.

3. Click on “Read from 0 to 9” to collect data stored in the PLC's data array:

If the values that you previously entered in Studio 5000 appear here, this confirms that the Modbus TCP communication is working as expected.

Congratulations, your PLC is now acting as a Modbus server and ready to be polled from a Modbus client!

Using an IoT Gateway as Modbus Client

In industrial automation, polling data from a Modbus server is often just the beginning. To unlock the full potential of this data, it’s essential to make it accessible for remote monitoring and analysis. This is where IoT gateways come into play.

IoT gateways combine traditional networking capabilities with advanced features like Modbus and MQTT communication. These devices act as a bridge, polling data from the Modbus server (in this case, your ControlLogix PLC) and forwarding it to cloud platforms or remote systems for visualization and processing.

Instead of using a simulated Modbus client, as demonstrated earlier, we’ll take it a step further by configuring an IoT gateway to function as the Modbus client. This approach enables seamless integration with IIoT solutions, providing real-time access to valuable operational data. Let’s walk through the process step by step.

We’ll use a Teltonika gateway in this example:

  1. Go to the login page of the Teltonika gateway using its IP address, which is usually “192.168.1.1” by default. Log in using the gateway’s credentials (usually found in the back of the device).

2. Once logged in, you should see an interface like the one below. Navigate to the “Modbus” section.

3. Since we are using our PLC as the server and our gateway as the client, make sure the “Modbus TCP slave” option is not enabled.

4. Go to the “Modbus TCP Master” tab. Here we will add the PLC as a slave device.

5. Click on “add”. Then configure the slave device’s parameters according to the details of your project. In our example, we have used the IP address and Modbus port (502 by default) of our PLC.

6. Scroll down to the section called “requests configuration”. Click on “add” and fill in the following fields according to your project: 

  • Name: Use a meaningful name for the data you want to read.
  • Data type: Choose the appropriate data type. 
  • Function: If you want to read only, select “read holding register”.
  • First register: The address of the PLC’s register.
  • Register count: The length of the data (how many registers it occupies).
  • Enabled: Check this option to poll data continuously.
  1. Now click on “test”. If the configuration was correct, you should see the PLC’s register value appear at the bottom. In our case, it shows the value “12345”, which was stored in the first register of our PLC.

8. Click on “save” to finish the process.

Now the gateway is polling data continuously from the PLC, acting as a Modbus client.

Frequently Asked Questions

What is the Modbus TCP Protocol?

Modbus TCP is an industrial communication protocol that enables data exchange over Ethernet networks. It builds on the traditional Modbus protocol by encapsulating messages within TCP/IP packets, making it ideal for modern automation systems. Widely used in industries, it allows seamless communication between programmable logic controllers (PLCs), sensors, HMIs, and SCADA systems. Known for its simplicity, Modbus TCP ensures compatibility across devices from different manufacturers, making it a preferred choice for efficient and reliable data transfer in industrial environments.

Does CompactLogix 5380 Support Modbus TCP?

The CompactLogix 5380 does not natively support Modbus TCP. However, it can be configured to work with Modbus TCP by using an "Add-On Instruction" (AOI), which is available for free from Rockwell Automation. This AOI allows the CompactLogix to communicate as a Modbus TCP server or client, enabling seamless integration with other Modbus-compatible devices.

What is CompactLogix?

CompactLogix is a series of programmable logic controllers (PLCs) developed by Rockwell Automation under the Allen-Bradley brand. Designed for medium-sized automation systems, it offers a balance of performance, scalability, and cost-effectiveness. CompactLogix PLCs provide powerful processing capabilities, support for multiple communication protocols, and seamless integration with Rockwell's Studio 5000 software. These features make CompactLogix a versatile solution for applications ranging from machine control to distributed systems, delivering reliable and efficient automation for industrial environments.

How to Collect Data from PLC to PC?

To get data from a PLC to a PC, you need to establish communication between the two devices using a compatible protocol, such as Modbus TCP or EtherNet/IP. First, configure the PLC to share specific data points, like tags or registers, that the PC can access. Then, connect the PLC to the PC via an Ethernet cable or through a network. Use SCADA software, an HMI application, or a custom program to read the data. Many software tools also allow you to log and analyze the collected data, providing valuable insights for your automation system.

Which Software Is Used to Program Allen-Bradley PLCs?

Allen-Bradley PLCs, including the CompactLogix series, are programmed using Studio 5000 Logix Designer. This powerful software provides an intuitive interface for creating and managing control system projects. It supports multiple programming languages like ladder logic, structured text, and function block diagrams, making it versatile for various automation tasks. Studio 5000 also streamlines development with features like tag-based programming and integrated configuration tools, ensuring efficient and reliable system design.

What Is an Allen-Bradley PLC?

An Allen-Bradley PLC is a programmable logic controller developed by Rockwell Automation, designed to automate and control industrial processes. Known for their reliability and flexibility, these controllers are used in a wide range of applications, from manufacturing lines to energy management systems. Allen-Bradley PLCs, such as the CompactLogix and ControlLogix series, provide powerful processing capabilities, support multiple communication protocols like EtherNet/IP and Modbus TCP, and integrate seamlessly with Studio 5000 software. They are a cornerstone of modern industrial automation, enabling efficient, precise, and scalable control solutions.

What Software Is Used to Define the Data Configuration of Allen-Bradley PLCs?

The data configuration of Allen-Bradley PLCs is defined using Studio 5000 Logix Designer. This software allows you to create and manage tags, map data points, and set up communication parameters for seamless integration with other devices. With its intuitive interface and versatile tools, Studio 5000 makes it easy to configure data for protocols like Modbus TCP and EtherNet/IP, ensuring efficient and reliable communication in industrial automation systems.

Which Is Better for Data Collection, Modbus RTU or Modbus TCP/IP?

The choice between Modbus RTU and Modbus TCP/IP depends on your specific application needs. Modbus RTU is ideal for smaller networks and legacy systems, as it operates over serial communication (RS-232 or RS-485) and is cost-effective for short-distance data collection. However, Modbus TCP/IP is better suited for modern, large-scale networks. It leverages Ethernet, enabling faster data transfer, greater scalability, and support for multiple simultaneous connections. For industrial systems requiring seamless integration with IIoT or SCADA platforms, Modbus TCP/IP is often the preferred choice.

How Do I Send PLC Data to the Cloud?

To send PLC data to the cloud, start by connecting your PLC to an industrial gateway or an edge device that supports cloud communication. Configure the gateway to retrieve data from the PLC using protocols like Modbus TCP or EtherNet/IP. Then, set up the gateway to forward this data to your cloud platform via MQTT, HTTPS, or another compatible protocol. Many platforms also offer dedicated APIs or connectors to streamline integration. For advanced solutions, consider using IIoT platforms that can process and analyze the data directly in the cloud, enabling real-time insights and decision-making.