DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
modbus.h File Reference

Zero-heap Modbus TCP slave/server (Modbus Application Protocol v1.1b3). More...

#include "ServerConfig.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Detailed Description

Zero-heap Modbus TCP slave/server (Modbus Application Protocol v1.1b3).

Split like the CoAP/SNMP services into a pure, host-testable core and an ESP32-only TCP transport:

  • modbus_process_adu() takes a complete Modbus TCP ADU (MBAP header + PDU) and produces the response ADU in a caller buffer - no sockets, no heap. It is unit-tested on the host (env:native_modbus).
  • modbus_rx() is the ConnProto::PROTO_MODBUS data handler dispatched by the session layer; it frames ADUs out of the rx ring and feeds them through modbus_process_adu(). The slave keeps no per-connection state (a partial frame waits in the rx ring), so no accept/close hooks are needed. Open the port with listen(502, ConnProto::PROTO_MODBUS).

The data model is four fixed BSS tables (coils, discrete inputs, holding registers, input registers). The application reads and writes them with the accessors below; a write arriving from a client also fires modbus_on_write().

Supported function codes: 0x01 Read Coils, 0x02 Read Discrete Inputs, 0x03 Read Holding Registers, 0x04 Read Input Registers, 0x05 Write Single Coil, 0x06 Write Single Register, 0x0F Write Multiple Coils, 0x10 Write Multiple Registers. Any other function code returns exception 0x01 (Illegal Function).

Modbus has no authentication or encryption - run it only on a trusted network.

Definition in file modbus.h.