Skip to main content
Version: Next

Modbus server

The Modbus Server module (io.scadex.server.modbus) makes the gateway a Modbus TCP server. A register map puts tags at Modbus addresses, and a PLC, an HMI or another SCADA system reads them as it would read any device. This page is for engineers and administrators who open the gateway to Modbus clients. It is the other direction of the Modbus TCP driver, which reads devices.

It has no third-party dependency and declares SDK contract 1.2.

What has been proven​

The server has been run against the repository's own Modbus client. No PLC or SCADA master has been tried yet.

Turning it on​

Open Gateway, then Modbus server. The server is off until an administrator turns it on, and read-only until they allow writes. The page header says on which port it listens while it does, and a strip of facts under it shows State, Clients (with how many were turned away), Requests (with how many were reads, writes and refusals), Writes (Allowed or Not allowed) and Tags (how many of the mapped tags are good).

WhereSettingMeaningDefault
composeSCADEX_MODBUS_BINDThe host address the port is published on. A LAN address serves the plant network, 0.0.0.0 every interface.127.0.0.1
composeSCADEX_MODBUS_PORTThe port on the host. 502 is the usual Modbus port.1502
containerSCADEX_MODBUS_SERVER_PORTThe port inside the container.1502

A port that is taken is reported as failed on the page and tried again every 15 seconds. At most 128 clients are connected at once.

The register map​

Each row maps one tag to an address:

FieldMeaning
TagThe tag's path. Its engineering value, after scaling, is what a client reads.
Areaholding (4x), input (3x), coil (0x) or discrete (1x).
AddressCounted from 0, as a client sends it. The register a PLC manual calls 40001 is address 0 in holding.
Data typebool, int16, uint16, int32, uint32, int64, uint64, float32, float64 or string (with a length in registers). A coil or discrete input is always bool.
Byte orderOptional. The row's own order instead of the server's. See byte and word order.
WritableWhether a client may write the tag through this row. Only holding and coil rows can be.

Rows can't overlap. Map several tags lays tags out one after another from a first address, each after the one before, whatever its size.

What a client reads​

The server answers function codes 1, 2, 3 and 4 from a register image that holds each mapped tag's last good value. It starts from the tags' current values and follows the gateway's value feed.

  • Modbus carries no quality. A tag that is bad keeps its last good value in the image. The page counts rows that are good, bad, waiting (no value yet) or in error, and says why.
  • A value that doesn't fit its row, such as 70000 in a uint16, leaves the image as it was and marks the row in error.
  • A read that touches an address no row covers is refused with "illegal data address". With Refuse unmapped addresses off, such addresses read as 0.
  • A read is up to 125 registers or 2000 bits.

What a client may write​

Nothing, until an administrator allows writes. With writes off, function codes 5, 6, 15 and 16 answer "illegal function".

With writes on, a client may write rows marked writable, and only whole rows. A write that reaches half of a float32, a row that isn't writable or an address nothing maps is refused with "illegal data address" before anything is written. Each row written is a tag write by the principal modbus:<client address>, which shows in the write audit log. If the gateway refuses the write, the client gets "server device failure", and rows of the same request written before it stay written. A written value is in the image at once, and the tag's own value follows through the feed.

Who may connect​

Modbus TCP has no login. Allowed clients lists addresses and networks (10.0.0.5, 10.0.0.0/24); empty allows any, and a client that isn't listed is hung up on and counted. Unit ids limits the units answered; any other unit gets "gateway target device failed to respond". Leave writes off unless the clients are trusted.

API​

Under /api/v1/modules/io.scadex.server.modbus:

RouteRoleMeaning
GET /statusany signed-in userState, port, counts of clients and requests, and rows by state
GET /settings, GET /map, GET /clientsengineerSettings, the map with each row's state and value, connected clients
PUT /settingsadministratorenabled, allowWrites, allowedClients, unitIds, byteOrder, refuseUnmapped
POST /map, PUT /map/{id}, DELETE /map/{id}administratorChange a row
POST /map/layoutadministratorMap tagPaths one after another from start