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

    Class TcpTransportService

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

    • AsyncTcpTransport — Upstream modbus-rs TCP transport.
    • TcpTransportOpenOptions — Configuration for the TCP connection.
    • createTransportScoped — Generic lifecycle logic from shared-transport.

    Hierarchy

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

      • _: never

      Returns TcpTransportService

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

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