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

    Class WasmAsciiTransportService

    Scoped Effect service wrapping modbus-rs's browser WasmAsciiTransport for Modbus ASCII over the Web Serial API. The caller obtains the port handle; this service does not request browser permission.

    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 WasmAsciiTransport.createClient and cached, so repeated requests for the same unit ID reuse the same client.

    • WasmAsciiTransport — Upstream modbus-rs browser Web Serial ASCII transport.
    • requestSerialPort — Obtains the serial port handle this service's port option needs.
    • createTransportScoped — Generic lifecycle logic from shared-transport.

    Hierarchy

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

      • _: never

      Returns WasmAsciiTransportService

    makeScoped: (
        ...args: [
            options: WasmSerialTransportOptions & { port: WasmSerialPortHandle } & 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,
    > = ...

    Builds the scoped transport service effect. The transport opens on first use and its connection closes when the consuming scope ends.

    Type Declaration

      • (
            ...args: [
                options: WasmSerialTransportOptions & { port: WasmSerialPortHandle } & 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,
        >
      • Parameters

        Returns 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,
        >

        An effect that provides the service for the lifetime of its scope.

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

      Accepts an array of SlaveDeviceDefinitions 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: WasmSerialTransportOptions & { port: WasmSerialPortHandle } & TransportResilienceOptions & MockFaultOptions,
      ) => Layer<WasmAsciiTransportService, never, never>

      A function that takes WasmAsciiTransportOpenOptions and returns a scoped Layer providing the mock service. The mock uses device definitions and fault hooks instead of browser I/O.

      makeMockTransport — The underlying mock factory.