@flux-control/effect-modbus-rs
    Preparing search index...

    Function tcpGatewayLayer

    • 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.

      Parameters

      • options: GatewayBindOptions

        Gateway bind options (host, port).

      • gatewayConfig: GatewayConfig

        Routing configuration with downstream server definitions and a unit-ID-to-channel route table.

      Returns Layer<never, ModbusError>

      A layer that starts the gateway; bind failures enter the ModbusError channel. Scope finalization shuts it down, and shutdown failures are ignored.

      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);
      • GatewayBindOptions — Options for the gateway bind address.
      • GatewayConfig — Configuration for downstream servers and routing.