Modbus Connector
Overview
Section titled “Overview”The Modbus connector enables communication with PLCs and industrial devices using the Modbus protocol, supporting both serial (RTU) and TCP/IP connections.
Connector Types:
ModbusReader- Read data from Modbus devicesModbusWriter- Write data to Modbus devices
Features
Section titled “Features”- ✅ Multiple transport protocols (TCP, RTU, UDP, TLS)
- ✅ All register types (Holding, Input, Coil, Discrete Input)
- ✅ Multiple data types (Int16/32/64, UInt16/32/64, Float32/64, ASCII)
- ✅ Configurable byte and word order
- ✅ Unit ID support for multi-device networks
Transport Protocols
Section titled “Transport Protocols”Meddle supports the following Modbus transports:
TCP- Modbus TCP over EthernetTCPWithTLS- Modbus TCP with TLS encryptionUDP- Modbus over UDPRTU- Modbus RTU over serialRTUOverTCP- Modbus RTU encapsulated in TCPRTUOverUDP- Modbus RTU encapsulated in UDP
Basic Configuration
Section titled “Basic Configuration”Modbus TCP Reader
Section titled “Modbus TCP Reader”{ "type": "ModbusReader", "config": { "endpoint": "192.168.1.100:502", "transport": "TCP", "pollingRate": 1000, "defaultUnitId": 1, "defaultBitOrder": "BigEndian", "defaultWordOrder": "HighFirst" }, "variables": [ { "key": "temperature", "address": 0, "registerType": "HoldingRegister", "dataType": "Float64" }, { "key": "pressure", "address": 4, "registerType": "HoldingRegister", "dataType": "Int32" } ]}Modbus RTU Reader
Section titled “Modbus RTU Reader”{ "type": "ModbusReader", "config": { "endpoint": "/dev/ttyUSB0", "transport": "RTU", "pollingRate": 1000, "defaultUnitId": 1, "baudRate": 9600, "dataBits": 8, "parity": "None", "stopBits": 1 }, "variables": [ { "key": "sensor_value", "address": 0, "registerType": "InputRegister", "dataType": "UInt16" } ]}Modbus Writer
Section titled “Modbus Writer”{ "type": "ModbusWriter", "config": { "endpoint": "192.168.1.100:502", "transport": "TCP", "defaultUnitId": 1 }, "variables": [ { "key": "setpoint", "address": 100, "registerType": "HoldingRegister", "dataType": "Float32" }, { "key": "enable", "address": 0, "registerType": "Coil" } ]}Register Types
Section titled “Register Types”Holding Registers (Read/Write)
Section titled “Holding Registers (Read/Write)”General-purpose registers that can be read and written.
{ "key": "temperature", "address": 0, "registerType": "HoldingRegister", "dataType": "Float64"}Function Codes: Read (03), Write Single (06), Write Multiple (16)
Input Registers (Read-Only)
Section titled “Input Registers (Read-Only)”Read-only registers typically used for sensor data.
{ "key": "sensor_reading", "address": 0, "registerType": "InputRegister", "dataType": "Int16"}Function Code: Read (04)
Coils (Read/Write Boolean)
Section titled “Coils (Read/Write Boolean)”Single-bit registers for digital outputs.
{ "key": "motor_enable", "address": 0, "registerType": "Coil"}Function Codes: Read (01), Write Single (05), Write Multiple (15)
Discrete Inputs (Read-Only Boolean)
Section titled “Discrete Inputs (Read-Only Boolean)”Read-only single-bit registers for digital inputs.
{ "key": "limit_switch", "address": 0, "registerType": "DiscreteInput"}Function Code: Read (02)
Data Types
Section titled “Data Types”Integer Types
Section titled “Integer Types”// Signed 16-bit integer (-32768 to 32767){"dataType": "Int16"} // 1 register
// Unsigned 16-bit integer (0 to 65535){"dataType": "UInt16"} // 1 register// Signed 32-bit integer{"dataType": "Int32"} // 2 registers
// Unsigned 32-bit integer{"dataType": "UInt32"} // 2 registers// Signed 64-bit integer{"dataType": "Int64"} // 4 registers
// Unsigned 64-bit integer{"dataType": "UInt64"} // 4 registersFloating Point Types
Section titled “Floating Point Types”// 32-bit float (4 bytes){"dataType": "Float32"} // 2 registers
// 64-bit float (8 bytes){"dataType": "Float64"} // 4 registersString Types
Section titled “String Types”// ASCII character (1 byte per register){"dataType": "AsciiChar"} // 1 registerByte and Word Order
Section titled “Byte and Word Order”Modbus devices may use different byte and word ordering. Configure these to match your device:
Bit Order (Byte Order)
Section titled “Bit Order (Byte Order)”{ "defaultBitOrder": "BigEndian" // or "LittleEndian"}- BigEndian: Most significant byte first (default, most common)
- LittleEndian: Least significant byte first
Word Order
Section titled “Word Order”For multi-register values (32-bit, 64-bit):
{ "defaultWordOrder": "HighFirst" // or "LowFirst"}- HighFirst: High word first (default)
- LowFirst: Low word first
Per-Variable Override
Section titled “Per-Variable Override”{ "key": "special_value", "address": 10, "registerType": "HoldingRegister", "dataType": "Float32", "bitOrder": "LittleEndian", "wordOrder": "LowFirst"}RTU Serial Configuration
Section titled “RTU Serial Configuration”For Modbus RTU over serial connections:
{ "endpoint": "/dev/ttyUSB0", "transport": "RTU", "baudRate": 9600, "dataBits": 8, "parity": "None", "stopBits": 1, "timeout": 1000}Parameters:
baudRate: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200dataBits: 7 or 8parity: None, Even, OddstopBits: 1 or 2timeout: Read timeout in milliseconds
Unit ID (Slave Address)
Section titled “Unit ID (Slave Address)”Modbus supports multiple devices on the same network using Unit IDs:
{ "defaultUnitId": 1 // Default for all variables}Per-variable override:
{ "key": "device2_temp", "address": 0, "registerType": "HoldingRegister", "dataType": "Float32", "unitId": 2 // Override for this variable}Common Use Cases
Section titled “Common Use Cases”1. Energy Meter Reading
Section titled “1. Energy Meter Reading”{ "type": "ModbusReader", "config": { "endpoint": "192.168.1.50:502", "transport": "TCP", "pollingRate": 5000, "defaultUnitId": 1 }, "variables": [ { "key": "voltage", "address": 0, "registerType": "InputRegister", "dataType": "Float32" }, { "key": "current", "address": 2, "registerType": "InputRegister", "dataType": "Float32" }, { "key": "power", "address": 4, "registerType": "InputRegister", "dataType": "Float32" }, { "key": "energy", "address": 6, "registerType": "InputRegister", "dataType": "Float64" } ]}2. PLC Control
Section titled “2. PLC Control”{ "type": "ModbusWriter", "config": { "endpoint": "192.168.1.100:502", "transport": "TCP", "defaultUnitId": 1 }, "variables": [ { "key": "motor_speed", "address": 100, "registerType": "HoldingRegister", "dataType": "UInt16" }, { "key": "motor_start", "address": 0, "registerType": "Coil" }, { "key": "motor_stop", "address": 1, "registerType": "Coil" } ]}3. Multi-Device Network
Section titled “3. Multi-Device Network”{ "type": "ModbusReader", "config": { "endpoint": "/dev/ttyUSB0", "transport": "RTU", "pollingRate": 1000, "baudRate": 9600 }, "variables": [ { "key": "device1_temp", "address": 0, "registerType": "HoldingRegister", "dataType": "Float32", "unitId": 1 }, { "key": "device2_temp", "address": 0, "registerType": "HoldingRegister", "dataType": "Float32", "unitId": 2 }, { "key": "device3_temp", "address": 0, "registerType": "HoldingRegister", "dataType": "Float32", "unitId": 3 } ]}Troubleshooting
Section titled “Troubleshooting”Connection Timeout
Section titled “Connection Timeout”Solutions:
- Verify endpoint address and port
- Check network connectivity
- Increase timeout value
- Verify device is powered and responsive
Invalid Data
Section titled “Invalid Data”Solutions:
- Check byte order (
BigEndianvsLittleEndian) - Verify word order (
HighFirstvsLowFirst) - Confirm data type matches device specification
- Verify register address is correct
RTU Communication Errors
Section titled “RTU Communication Errors”Solutions:
- Check serial cable connections
- Verify baud rate matches device
- Confirm parity and stop bits settings
- Check for proper termination resistors
- Reduce polling rate to avoid bus collisions
Exception Codes
Section titled “Exception Codes”Common Modbus exception codes:
- 01: Illegal Function
- 02: Illegal Data Address
- 03: Illegal Data Value
- 04: Slave Device Failure
Best Practices
Section titled “Best Practices”- Start with Read-Only: Test with Input Registers before writing
- Use Appropriate Polling: Don’t poll faster than device can respond
- Group Consecutive Registers: More efficient than scattered reads
- Document Byte Order: Keep notes on device-specific configurations
- Test Unit IDs: Verify each device responds to its Unit ID
Related Connectors
Section titled “Related Connectors”- OPC UA - Alternative industrial protocol
- Siemens S7 - Direct Siemens PLC communication
- Filter - Filter Modbus data
- SQL Writer - Store Modbus data in databases