How to Communicate Between Two PLCs: Methods and Examples
To communicate between two PLCs, use industrial communication protocols such as
Modbus, Ethernet/IP, or serial communication. Configure one PLC as a master and the other as a slave, then exchange data via shared registers or messages over the chosen protocol.Syntax
Communication between two PLCs typically involves setting up a master-slave relationship using a protocol like Modbus TCP. The master PLC sends requests, and the slave PLC responds with data.
Key parts include:
- Master PLC: Initiates communication and requests data.
- Slave PLC: Responds with requested data or accepts commands.
- Registers/Tags: Memory locations used to exchange data.
- Protocol: Defines the rules for data exchange (e.g., Modbus TCP, Ethernet/IP).
plaintext
Master PLC Modbus TCP Read Request: READ_HOLDING_REGISTERS(slave_address, start_register, quantity) Slave PLC Modbus TCP Response: RETURN register_values
Example
This example shows two PLCs communicating using Modbus TCP. The master PLC reads holding registers from the slave PLC.
javascript
/* Master PLC Pseudocode for Modbus TCP Read */ const slaveAddress = 1; const startRegister = 100; const quantity = 4; function readRegisters() { const data = modbusTCP.readHoldingRegisters(slaveAddress, startRegister, quantity); console.log('Received data:', data); } readRegisters(); /* Slave PLC setup: Holds registers 100-103 with values */ registers[100] = 123; registers[101] = 456; registers[102] = 789; registers[103] = 1011;
Output
Received data: [123, 456, 789, 1011]
Common Pitfalls
- Incorrect addressing: Using wrong register addresses causes no data or wrong data to be exchanged.
- Protocol mismatch: Both PLCs must use the same communication protocol and settings.
- Network issues: Firewalls or wrong IP addresses block communication.
- Timing problems: Master requests too fast or slave response delays cause errors.
javascript
/* Wrong way: Master uses wrong slave address */ const wrongSlaveAddress = 2; // Slave is actually 1 const data = modbusTCP.readHoldingRegisters(wrongSlaveAddress, 100, 4); console.log('Data:', data); // Likely error or empty /* Right way: Correct slave address */ const correctSlaveAddress = 1; const dataCorrect = modbusTCP.readHoldingRegisters(correctSlaveAddress, 100, 4); console.log('Data:', dataCorrect);
Output
Data: undefined
Data: [123, 456, 789, 1011]
Quick Reference
| Concept | Description |
|---|---|
| Master PLC | Initiates communication and requests data |
| Slave PLC | Responds to master with data or status |
| Registers/Tags | Memory locations used to exchange data |
| Modbus TCP | Common protocol for PLC communication over Ethernet |
| Ethernet/IP | Another popular industrial Ethernet protocol |
| Serial Communication | RS-232/RS-485 for direct PLC connections |
| Common Issues | Addressing errors, protocol mismatch, network problems |
Key Takeaways
Use a common industrial protocol like Modbus TCP or Ethernet/IP for PLC communication.
Set one PLC as master and the other as slave to organize data exchange.
Ensure both PLCs use matching communication settings and correct register addresses.
Test network connectivity and firewall settings to avoid communication blocks.
Start with simple read/write commands before implementing complex data exchanges.