How to Configure Modbus TCP on Allen-Bradley CompactLogix (Studio 5000 Step-by-Step)

By | April 10, 2026

Allen-Bradley CompactLogix and ControlLogix PLCs do not support Modbus TCP natively. Their primary protocol is EtherNet/IP. But in many industrial systems, you need to communicate with Modbus TCP devices — energy meters, VFDs, third-party sensors, or legacy equipment.

Rockwell Automation provides a free solution: Modbus TCP Add-On Instructions (AOIs). These are pre-built function blocks you import into Studio 5000. They use the controller’s built-in socket services to communicate over Modbus TCP without any extra hardware modules.

The AOIs come in two versions:

  • Modbus TCP Client AOI — the PLC acts as master, polling external Modbus devices
  • Modbus TCP Server AOI — the PLC acts as slave, letting SCADA and HMI systems read its data

This guide covers both configurations step by step — from downloading the AOI to testing communication with real devices.

1. Requirements and Compatibility

ItemRequirement
ControllerCompactLogix 5370/5380/5480 or ControlLogix 5570/5580
FirmwareV20+ (V31+ recommended for best socket performance)
SoftwareStudio 5000 Logix Designer V20+
Ethernet moduleBuilt-in Ethernet port (CompactLogix) or 1756-EN2T/EN3TR (ControlLogix)
AOI versionV2.04.00 or later (free from Rockwell)
Additional hardwareNone — the AOI uses built-in socket services

⚠️ Important: The older 1756-ENBT module does NOT support socket communication. You must use the 1756-EN2T (Series B or later) or the built-in Ethernet port on CompactLogix for Modbus TCP to work.

2. How Modbus TCP Works on CompactLogix

Since CompactLogix does not have a native Modbus TCP stack, the AOI builds Modbus TCP frames in PLC memory and sends them using CIP socket services — the same TCP/IP socket layer used by EtherNet/IP.

ModeAOIPLC RoleHow It Works
ClientMOD_ClientMaster — sends requestsPLC opens a TCP socket to the target device on port 502, builds Modbus TCP frames, sends them, and parses responses
ServerMOD_ServerSlave — receives requestsPLC listens on port 502 for incoming TCP connections, parses Modbus requests, and responds from a holding register array

The AOI handles all the protocol details — MBAP header, function codes, transaction IDs, and error handling. You just configure the parameters and map the data.

Performance Limitations

Because the AOI uses socket services (not dedicated hardware), it is slower than a native protocol implementation:

  • Minimum reliable poll rate: 100–500 ms per transaction
  • Faster rates increase CPU load significantly
  • Suitable for monitoring and slow control — not for high-speed real-time applications
  • For high-performance Modbus TCP, use a dedicated hardware gateway

3. Downloading the Modbus TCP AOI

  1. Go to the Rockwell Automation Sample Code Library (search for “Modbus TCP AOI” on rockwellautomation.com)
  2. Download the file: “Modbus TCP Add-On Instructions for ControlLogix and CompactLogix Controllers” (AOI Version 2.04.00 or later)
  3. The download contains:
    • .L5X files for the Client and Server AOIs
    • A User Manual (PDF) with parameter descriptions
    • Example programs

Save these files to your project folder.

4. Importing the AOI into Studio 5000

Step 1. Open Your Project

Open your existing Studio 5000 project or create a new one with your CompactLogix/ControlLogix controller.

Step 2. Import the AOI

Right-click on Add-On Instructions in the Controller Organizer → Import Add-On Instruction → browse to the downloaded .L5X file.

Import both:

  • MOD_Client (for client/master mode)
  • MOD_Server (for server/slave mode)

Or import only the one you need.

Step 3. Create a Periodic Task

Rockwell recommends running the Modbus AOI in a Periodic Task, not in the Continuous Task. This ensures consistent execution timing.

Right-click TasksNew Task:

SettingValue
NameModbusTask
TypePeriodic
Period20 ms (minimum 10 ms, but 20 ms is recommended to reduce CPU load)

Create a new Program and Routine inside this task for your Modbus logic.

5. Step-by-Step: Configure as Modbus TCP Client

The client AOI makes the PLC act as a Modbus master — it polls external devices.

Step 1. Create Tags

Create the following controller-scoped tags:

Tag NameData TypePurpose
MB_ClientMOD_ClientInstance of the client AOI
MB_ClientDataSINT[256]Buffer for received data
ClientConfigUser-definedConfiguration structure (IP, port, registers)

Step 2. Add the AOI to Your Routine

In your Modbus routine, add a rung with the MOD_Client AOI instruction.

Step 3. Configure the Client Parameters

ParameterValueMeaning
CnxnEnable1 (TRUE)Enable the connection
IP_AddrTarget device IP (e.g., “192.168.1.100”)IP address of the Modbus server
IP_Port502TCP port
UnitID1Modbus Unit Identifier (slave address)
MsgType00 = Read Holding Registers (FC 03)
RegStart0Starting register address (0-based)
RegCount10Number of registers to read
DataPtrMB_ClientDataPointer to the data buffer

Step 4. Trigger the Request

Set CnxnEnable = TRUE. The AOI automatically opens the TCP connection, sends the read request, and stores the response in the DataPtr buffer.

Monitor CnxnStatus for connection state and MsgStatus for transaction results.

6. Client AOI Parameters Explained

ParameterDirectionTypeDescription
CnxnEnableInputBOOLTRUE = open/maintain connection. FALSE = close.
IP_AddrInputSTRINGTarget device IP address
IP_PortInputINTTCP port (default 502)
UnitIDInputINTModbus Unit ID (1–247)
MsgTypeInputINT0 = Read Holding Reg (FC 03), 1 = Read Input Reg (FC 04), 2 = Write Single Reg (FC 06), 3 = Write Multiple Reg (FC 16), 4 = Read Coils (FC 01), 5 = Read Discrete Inputs (FC 02), 6 = Write Single Coil (FC 05), 7 = Write Multiple Coils (FC 15)
RegStartInputDINTStarting register/coil address (0-based)
RegCountInputINTNumber of registers/coils
DataPtrInOutSINT[]Data buffer for read/write values
CnxnStatusOutputDINTConnection status (0 = idle, 1 = connecting, 2 = connected, 3 = error)
MsgStatusOutputDINTMessage status (0 = idle, 1 = sending, 2 = done, 3 = error)
MsgErrorOutputDINTError code from the last failed transaction

MsgType Reference

MsgTypeModbus FunctionAction
0FC 03Read Holding Registers
1FC 04Read Input Registers
2FC 06Write Single Register
3FC 16Write Multiple Registers
4FC 01Read Coils
5FC 02Read Discrete Inputs
6FC 05Write Single Coil
7FC 15Write Multiple Coils

7. Polling Multiple Devices

The AOI can handle one transaction at a time per instance. To poll multiple devices or multiple register ranges, you have two options:

Option A: Multiple AOI Instances

Create a separate MOD_Client instance for each device. Each runs independently with its own TCP connection.

InstanceTarget DeviceRegisters
MB_Client_Meter1192.168.1.100Read 40001–40020
MB_Client_Meter2192.168.1.101Read 40001–40020
MB_Client_VFD1192.168.1.200Read 40001–40010

This is simple but uses more CPU and socket resources.

Option B: Sequencer with One Instance

Use a step counter to cycle through different read/write operations:

// Step 0: Read voltage from Meter 1
IF Step = 0 AND MB_Client.MsgStatus = 2 THEN
    // Copy data from buffer
    Meter1_Voltage := MB_ClientData[0];
    // Reconfigure for next read
    MB_Client.IP_Addr := '192.168.1.101';
    MB_Client.RegStart := 0;
    MB_Client.RegCount := 10;
    Step := 1;
END_IF;

// Step 1: Read voltage from Meter 2
IF Step = 1 AND MB_Client.MsgStatus = 2 THEN
    Meter2_Voltage := MB_ClientData[0];
    // Reconfigure for next read
    MB_Client.IP_Addr := '192.168.1.100';
    MB_Client.RegStart := 0;
    MB_Client.RegCount := 10;
    Step := 0;
END_IF;

This uses fewer resources but is slower (each device is polled every N × cycle time).

8. Step-by-Step: Configure as Modbus TCP Server

The server AOI makes the PLC act as a Modbus slave — external systems read and write its data.

Step 1. Create Tags

Tag NameData TypePurpose
MB_ServerMOD_ServerInstance of the server AOI
MB_HoldRegsINT[100]Holding register array (exposed to Modbus clients)

Step 2. Add the AOI to Your Routine

Add the MOD_Server instruction to a rung in your Modbus routine.

Step 3. Configure Parameters

ParameterValueMeaning
SrvrEnable1 (TRUE)Enable the server
IP_Port502TCP port to listen on
UnitID1Unit ID this server responds to
HoldRegPtrMB_HoldRegsPointer to the holding register array
HoldRegCount100Number of holding registers

Step 4. Populate Holding Registers

In your PLC program, copy process values into the holding register array:

MB_HoldRegs[0] := Motor_Speed;
MB_HoldRegs[1] := Temperature;
MB_HoldRegs[2] := Pressure;
MB_HoldRegs[10] := Alarm_Status;

Step 5. Test

Connect a Modbus TCP client (ModbusPoll, SCADA, or HMI) to the PLC’s IP on port 502. Read holding registers starting at address 0. The values should match what your PLC program writes to MB_HoldRegs.

9. Server AOI Parameters Explained

ParameterDirectionTypeDescription
SrvrEnableInputBOOLTRUE = start listening. FALSE = stop.
IP_PortInputINTTCP port to listen on (default 502)
UnitIDInputINTUnit ID to respond to (0 = respond to all)
HoldRegPtrInOutINT[]Pointer to holding register array
HoldRegCountInputINTSize of holding register array
InputRegPtrInOutINT[]Pointer to input register array (optional)
CoilPtrInOutDINT[]Pointer to coil data (optional)
SrvrStatusOutputDINTServer status
ClientConnectedOutputBOOLTRUE when a client is connected
WriteEventOutputBOOLTRUE for one scan when a client writes data

10. Data Type Mapping Between Modbus and Logix

Allen-Bradley PLCs use different data types than the Modbus 16-bit register model.

Modbus DataLogix Data TypeNotes
1 register (16-bit unsigned)INTDirect mapping
1 register (16-bit signed)INTSame — Logix INT is signed by default
2 registers (32-bit integer)DINTCombine two consecutive INT values
2 registers (32-bit float)REALCombine two INT into DINT, then copy to REAL
Coil (1 bit)BOOLMap to individual bits
Bitmask registerDINTUse bit-level addressing (e.g., Tag.0, Tag.1)

Converting 32-Bit Float

Modbus registers 0 and 1 contain a FLOAT32 value (big-endian AB CD):

// Combine two 16-bit registers into a 32-bit float
TempDINT := (MB_ClientData[0] * 65536) + MB_ClientData[1];
COP(TempDINT, ActivePower, 1);  // Copy bits from DINT to REAL

⚠️ Warning: Byte order varies by device. If the float value looks wrong, swap registers 0 and 1. See: Modbus Register Map Explained

11. Alternative: Using a Hardware Gateway

If the AOI approach is too slow or consumes too much CPU, use a dedicated Modbus TCP to EtherNet/IP gateway.

GatewayManufacturerMax DevicesCommunication
Anybus AB7072HMS Networks32 Modbus slavesEtherNet/IP adapter to PLC
Red Lion DA30DRed Lion32 Modbus slavesEtherNet/IP adapter
ProSoft MVI56E-MNETProSoft (Belden)30 connectionsControlLogix backplane module
ICC ETH-1000ICC20+ devicesEtherNet/IP adapter

How It Works

  1. The gateway connects to Modbus TCP devices on port 502.
  2. The gateway maps Modbus registers to EtherNet/IP produced/consumed tags.
  3. The PLC reads the gateway as a standard EtherNet/IP device — no AOI needed.
  4. Poll rates of 10–50 ms are achievable (much faster than the AOI method).

When to Use a Gateway vs AOI

CriteriaUse AOIUse Gateway
Number of Modbus devices1–55–30+
Required poll rate> 500 ms< 500 ms
CPU load concernLow (small program)High (many tasks)
BudgetFree (AOI)$200–$1,000 per gateway
Reliability requirementMonitoring onlyControl and protection

12. Common Errors and How to Fix Them

ErrorSymptomCauseFix
CnxnStatus = 3Connection failedWrong IP, device offline, or firewall blocking port 502Ping the device. Check port 502 with nc -zv IP 502.
MsgStatus = 3Transaction errorWrong register address, wrong MsgType, or device rejected the requestCheck the device register map. Verify 0-based vs 1-based addressing.
TimeoutNo responseDevice too slow or poll rate too fastIncrease timeout. Slow down the periodic task.
Socket errorAOI fails to open socket1756-ENBT used instead of EN2T, or max sockets exceededUse 1756-EN2T or built-in CompactLogix Ethernet port.
Data corruptionWrong valuesByte order mismatch for 32-bit valuesTry swapping the two 16-bit words.
CPU overloadPLC faults or slows downToo many AOI instances or task period too fastIncrease periodic task period to 50–100 ms. Reduce number of AOI instances.
Server not respondingSCADA shows timeoutSrvrEnable not set, or wrong UnitIDSet SrvrEnable = TRUE. Match UnitID in PLC to SCADA configuration.

13. Testing Your Configuration

Test Client Mode

  1. Run a Modbus Slave simulator on your PC (e.g., ModRSsim2 or Modbus Slave).
  2. Set the simulator to listen on port 502 with known register values.
  3. Configure the MB_Client AOI to connect to your PC’s IP.
  4. Trigger a read and verify received data matches the simulator.

Test Server Mode

  1. Enable the MB_Server AOI on the PLC.
  2. Open ModbusPoll or QModMaster on your PC.
  3. Connect to the PLC’s IP on port 502.
  4. Read holding registers and verify values match what your PLC program writes.

Verify with Wireshark

Capture traffic on port 502:

tcp.port == 502

You should see Modbus TCP request/response pairs with correct function codes, register addresses, and data values.

💡 Tip: Use the free Modbus Frame Decoder Tool to decode captured frames byte by byte.

Summary

Allen-Bradley CompactLogix and ControlLogix PLCs support Modbus TCP through Rockwell’s free Add-On Instructions. No extra hardware is needed for basic communication.

Key points:

  • Download the AOI from Rockwell’s Sample Code Library (free)
  • Run the AOI in a Periodic Task (20 ms recommended)
  • The AOI uses socket services — requires 1756-EN2T or built-in CompactLogix Ethernet port (not ENBT)
  • Client mode (MOD_Client): PLC polls external Modbus devices
  • Server mode (MOD_Server): SCADA/HMI reads PLC data over Modbus TCP
  • One transaction at a time per AOI instance — use a sequencer for multiple reads
  • Poll rates of 100–500 ms are realistic with the AOI approach
  • For faster polling or many devices, use a hardware gateway instead

The AOI approach works well for connecting a few meters or sensors. For large-scale Modbus integration, invest in a dedicated gateway.

Author: Zakaria El Intissar

I'm an automation and industrial computing engineer with 12 years of experience in power system automation, SCADA communication protocols, and electrical protection. I build tools and write guides for Modbus, DNP3, IEC 101/103/104, and IEC 61850 on ScadaProtocols.com to help engineers decode, analyze, and troubleshoot real industrial communication systems.

Leave a Reply

Your email address will not be published. Required fields are marked *