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

    Class RtuTransportService

    Scoped Effect service wrapping the modbus-rs AsyncRtuTransport for RTU (serial) Modbus communication.

    The transport connection is opened lazily on the first call to withClient(unitId) and automatically closed when the consuming scope finalizes.

    Clients are created per unitId via AsyncRtuTransport.createClient and cached, so repeated requests for the same unit ID reuse the same client.

    • AsyncRtuTransport — Upstream modbus-rs RTU transport.
    • RtuTransportOpenOptions — Configuration for the RTU serial port.
    • createTransportScoped — Generic lifecycle logic from shared-transport.

    Hierarchy

    • Shape<"RtuTransportService", TransportServiceApi, this>
      • RtuTransportService
    Index
    • Parameters

      • _: never

      Returns RtuTransportService

    makeScoped: (
        ...args: [options: RtuTransportOpenOptions & TransportResilienceOptions],
    ) => Effect<
        {
            batchingClient: (
                unitId: number,
            ) => Effect<BatchingModbusClient, ModbusError>;
            clearRequestTimeout: (
                ...args: [],
            ) => Effect<undefined, ModbusNotConnectedError, never>;
            close: (...args: [scope: Closeable]) => Effect<void, ModbusError, never>;
            connectionState: SubscriptionRef<
                {}
                | {}
                | { attempt: number }
                | { cause: ModbusError },
            >;
            hasPendingRequests: () => boolean;
            reconnect: (...args: []) => Effect<undefined, ModbusError, never>;
            setRequestTimeout: (
                ...args: [timeoutMs: number],
            ) => Effect<undefined, ModbusNotConnectedError, never>;
            withBatchingClient: (
                unitId: number,
                options?: BatchingClientOptions & { retry?: ModbusRetryPolicy },
            ) => Effect<
                BatchingModbusClient,
                ModbusUnitAlreadyDeclaredError
                | ModbusError,
            >;
            withClient: (
                ...args: [
                    unitId: number,
                    clientOptions?: { retry?: ModbusRetryPolicy },
                ],
            ) => Effect<EffectModbusClient, ModbusError, never>;
            get touchedUnits(): Set<number>;
        },
        never,
        Scope,
    > = ...

    Scoped constructor effect for the service. v4 does not auto-generate a layer from this, so RtuTransportService.make builds one explicitly.

    • Creates a Layer providing an in-memory mock RtuTransportService for testing or development.

      Accepts an array of SlaveDeviceDefinition values describing the simulated Modbus slaves and their register/coil maps.

      Parameters

      • devices: readonly {
            coils: readonly { address: number; default: boolean }[];
            discreteInputs: readonly { address: number; default: boolean }[];
            holdingRegisters: readonly { address: number; default: number }[];
            inputRegisters: readonly { address: number; default: number }[];
            unitId: number;
        }[]

        Slave device definitions for the mock.

      Returns (
          options: RtuTransportOpenOptions & TransportResilienceOptions & MockFaultOptions,
      ) => Layer<RtuTransportService, never, never>

      A factory that accepts transport, resilience, and mock-fault options and returns a layer for the mock service.

      makeMockTransport — The underlying mock factory.