The Modbus connector provides tag-based read and write access to a Modbus device over either TCP or RTU (serial), using the EasyModbus SDK.
Addressing follows the standard Modicon convention: an address's first digit selects the register type, with the remaining digits (adjusted for the type's offset and for 5- vs 6-digit addressing) giving the zero-based register/coil index. A start-end address range reads and combines multiple consecutive input/holding registers into a single value.
All communication with the device goes through a single lock, since EasyModbus (like most Modbus client libraries) is not safe for concurrent calls from multiple threads - the underlying request/response protocol requires strict ordering, and this connector's own read cycle and any external write can otherwise run on different threads at the same time.
The connector detects when the underlying connection is lost and reconnects automatically without blocking the read cycle - reconnection runs on its own dedicated background thread.
| Name | Values | Description |
|---|---|---|
| Type | MODBUS | The connector type identifier. |
| TYPE | TCP or RTU | Which Modbus transport to use. |
| IP | IP address or hostname | (TCP only) The device's address. |
| PORT | integer | (TCP only) The device's Modbus TCP port. |
| COMNAME | e.g. COM3 | (RTU only) The serial port name. |
| BAUDRATE | integer | (RTU only) Defaults to 9600. |
| PARITY | EVEN or (anything else) | (RTU only) Defaults to no parity unless EVEN is specified. |
| UNITID | byte (0-255) | The Modbus unit/slave identifier. Defaults to 0. |
| UpdateRate | milliseconds (integer) | How often the connector polls all subscribed tags. Defaults to 1000. |
| ReconnectDelay | milliseconds (integer) | Delay between reconnect attempts while the device is unreachable. Defaults to 5000. |
| Tag Type | Address | Behaviour |
|---|---|---|
| Any standard tag | 3xxxxx, e.g. 30001 | Input register. Read-only. |
| Any standard tag | 4xxxxx, e.g. 40001 | Holding register. Read/write. |
| Any standard tag | 2xxxxx, e.g. 20001 | Discrete input. Read-only, single point (no range support). |
| Any standard tag | 0xxxxx/1xxxxx, e.g. 10001 | Coil. Read/write, single point (no range support). |
| Any standard tag | start-end, e.g. 40001-40002 | A range of consecutive input or holding registers, combined into a single value. Read-only (input/holding registers accept writes only as single addresses). |
| Name | Arguments | Description |
|---|---|---|
| ReadData | Address | Reads a single address or range on demand, using the same addressing as a tag. |
| WriteData | Address, Value | Writes a single address on demand. |
The Address field of a tag follows the standard Modicon convention described above. The same values are also available on demand via RunMethod("READDATA"/"WRITEDATA") rather than through a polled tag, if a one-off read/write is preferred over continuous polling.
| Code | Type | Description |
|---|---|---|
| 1200 | Error | Unable to connect on startup |
| 1210 | Error | Missing TYPE parameter |
| 1215 | Error | Missing IP or PORT |
| 1225 | Error | Failed to connect |
| 1230 | Error | Missing COMNAME |
| 1240 | Error | Unrecognised TYPE - expected TCP or RTU |
| 1315 | Error | Left hand assignment of a Modbus address range is greater than the right hand assignment |
| 1320 | Error | Error reading a Modbus range |
| 1325 | Error | Error reading a Modbus address |
| 1405 | Error | Error writing to a tag's address |
| 1425 | Error | Error writing a Modbus address |
| 1510 | Error | RunMethod called with an unrecognised method name |
| 1520 | Error | RunMethod threw an unhandled exception |
| 2100 | Info | Connector started |
| 2205 | Info | Modbus client connecting |
| 2220 | Info | Connected via IP |
| 2235 | Info | Connected via COM Port |
| 2245 | Info | Controller connected |
| 2250 | Debug | HandleDisconnection event fired |
| 2255 | Debug | HandleConnection event fired |
| 2260 | Info | Client connection re-established |
| 2265 | Info | Reconnecting |
| 2270 | Debug | Invoking Connected event |
| 2275 | Debug | Invoking ConnectionLost event |
| 2300 | Debug | ReadUpdate cycle overran cycleDelay |
| 2305 | Debug | Error reading a tag's value |
| 2310 | Debug | Unrecognised Modbus address prefix (read) |
| 2400 | Debug | ITag not present - ChangeData called for an unregistered tag name |
| 2410 | Debug | Address is an input register - read-only, write ignored |
| 2415 | Debug | Address is a discrete input - read-only, write ignored |
| 2420 | Debug | Unrecognised Modbus address prefix (write) |
| 2500 | Debug | RunMethod called while not connected |