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

    Function tcpServerLayer

    • A scoped Layer that starts a Modbus TCP server.

      The server binds to the specified host and port, handling incoming Modbus requests via the provided ServerHandlers. The connection is automatically shut down when the consuming scope finalizes.

      Parameters

      • options: TcpServerOptions

        Server bind options (host, port, unit ID).

      • handlers: ServerHandlers

        Callback functions that handle incoming Modbus requests.

      Returns Layer<never, ModbusError>

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

      import { Effect, Layer } from "effect";
      import { tcpServerLayer } from "@flux-control/effect-modbus-rs";

      const ServerLive = tcpServerLayer(
      { host: "0.0.0.0", port: 502, unitId: 1 },
      { onReadCoils: (req) => [false, false] },
      );

      Layer.launch(ServerLive).pipe(Effect.runPromise);
      • TcpServerOptions — Options accepted by the upstream TCP server.
      • ServerHandlers — Interface for request handler callbacks.