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

    Function wasmSerialRtuServerLayer

    • A scoped Layer that starts a browser Modbus RTU server over the Web Serial API (experimental upstream surface).

      options.serialPort is the raw SerialPort object obtained from the consumer's own app code via navigator.serial.requestPort() (which has the dom lib types available) — not this package's requestSerialPort helper, which returns the WasmSerialPortHandle wrapper used only by the client-side transports (WasmRtuTransportService/WasmAsciiTransportService).

      Like wasmWsServerLayer, the WASM server requires a continuously-awaited serve() call to drive its request loop; this layer forks that call into the scope automatically so the returned Layer "just works".

      Parameters

      • options: WasmSerialServerOptions

        Serial port, baud rate, unit ID, etc.

      • handlers: ServerHandlers

        Callback functions that handle incoming Modbus requests (same ServerHandlers shape as the native TCP/serial servers).

      Returns Layer<never, ModbusError>

      A Layer that fails with ModbusError on bind failure.

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

      const port = await navigator.serial.requestPort(); // user-gesture gated
      const ServerLive = wasmSerialRtuServerLayer(
      { serialPort: port, unitId: 1, baudRate: 19200 },
      { onReadCoils: (req) => [false, false] },
      );

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