Gateway bind options (host, port).
Routing configuration with downstream server definitions and a unit-ID-to-channel route table.
A Layer that fails with ModbusError on bind failure.
import { Effect, Layer } from "effect";
import { tcpGatewayLayer } from "@flux-control/effect-modbus-rs";
const GatewayLive = tcpGatewayLayer(
{ host: "0.0.0.0", port: 8502 },
{
downstreams: [
{ host: "192.168.1.10", port: 502 },
{ host: "192.168.1.20", port: 502 },
],
routes: [
{ unitId: 1, channel: 0 },
{ unitId: 2, channel: 1 },
],
},
);
Layer.launch(GatewayLive).pipe(Effect.runPromise);
A scoped Layer that starts a Modbus TCP gateway.
The gateway binds to the specified host and port, forwarding incoming Modbus requests to downstream servers based on unit ID routing defined in the GatewayConfig. The gateway is automatically shut down when the consuming scope finalizes.