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

    Class AsciiTransportService

    Scoped Effect service wrapping the modbus-rs AsyncAsciiTransport for ASCII (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 AsyncAsciiTransport.createClient and cached, so repeated requests for the same unit ID reuse the same client.

    • AsyncAsciiTransport — Upstream modbus-rs ASCII transport.
    • AsciiTransportOpenOptions — Configuration for the ASCII serial port.
    • createTransportScoped — Generic lifecycle logic from shared-transport.

    Hierarchy

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

      • _: never

      Returns AsciiTransportService

    makeScoped: (
        ...args: [
            options: AsciiTransportOpenOptions & 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 AsciiTransportService.make builds one explicitly.

    • Creates a Layer providing an in-memory mock AsciiTransportService 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: AsciiTransportOpenOptions & TransportResilienceOptions & MockFaultOptions,
      ) => Layer<AsciiTransportService, 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.