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

    Interface BatchingModbusClient

    A client that decides its own transactions.

    CAUTION: This is not an EffectModbusClient and does not extend ModbusOperations. There is no writeSingleRegister and no readHoldingRegisters here. A raw write on this object would go around the cache and around the batch, so a value held for an address could reach the device after a newer value written past it. A caller that needs the raw surface as well gets it from withClient, which shares the same connection. Once a batching client exists for a unit, that raw client remains available for reads, coils, and the other non-register-write operations, but FC06, FC16, and FC23 fail with ModbusInvalidArgumentError. Mixing the two register write paths would bypass the pending batch and its cache.

    Coils are covered only when the declaration sets coils. Then coils batches FC01, FC05, and FC15, and raw FC05 and FC15 writes for the unit fail. Otherwise coil operations stay on the raw client.

    interface BatchingModbusClient {
        cache: RegisterCache | undefined;
        coils: BatchingCoilClient | undefined;
        debounce: BatchingDebounceWindows | undefined;
        flush: Effect<void>;
        inputs: BatchingRegisterReader;
        unitId: number;
        onShutdown(action: Effect<void, ModbusError>): Effect<void, never, Scope>;
        read(address: number): Effect<number, ModbusError>;
        readAll(
            addresses: readonly number[],
        ): Effect<readonly number[], ModbusError>;
        readAllNow(
            addresses: readonly number[],
        ): Effect<readonly number[], ModbusError>;
        readNow(address: number): Effect<number, ModbusError>;
        write(
            write: RegisterWrite,
            attributes?: ModbusSpanAttributes,
            options?: WriteOptions,
        ): Effect<void, ModbusError>;
        writeAll(
            writes: readonly RegisterWrite[],
            attributes?: ModbusSpanAttributes,
            options?: WriteOptions,
        ): Effect<void, ModbusError>;
        writeAllNow(
            writes: readonly RegisterWrite[],
            attributes?: ModbusSpanAttributes,
            options?: WriteOptions,
        ): Effect<void, ModbusError>;
        writeNow(
            write: RegisterWrite,
            attributes?: ModbusSpanAttributes,
            options?: WriteOptions,
        ): Effect<void, ModbusError>;
    }

    Hierarchy (View Summary)

    Index
    cache: RegisterCache | undefined

    The cache this client filters against, or undefined when cache is false.

    coils: BatchingCoilClient | undefined

    Batched coil operations, or undefined when the declaration did not set coils.

    debounce: BatchingDebounceWindows | undefined

    The debounce windows this client applies, or undefined when its declaration had no debounce option.

    The values are resolved and frozen when the client is built. An omitted maxHold shows as four times the write window.

    A caller that recovers an existing client with batchingClient did not choose these windows. Compare them with the windows that the caller expects.

    flush: Effect<void>

    Issues everything pending, now. Never fails: the outcome goes to the callers waiting on each batch.

    Reads over the input registers (FC04). The unqualified reads are holding registers (FC03).

    unitId: number

    The unit this client addresses.

    • Registers an action for the calling scope's finalization. Keep the transport open until that scope closes.

      The application selects the shutdown value. Use an immediate write method to avoid waiting for a collection window during cleanup.

      An unhandled failure is logged and raised as a defect. Other finalizers still run. Wrap the action in Effect.ignoreLogged to accept its failure.

      Parameters

      • action: Effect<void, ModbusError>

        Shutdown action to run before client teardown.

      Returns Effect<void, never, Scope>

      An effect that registers the action in the calling scope.

      const damper = yield* transport.withBatchingClient(3);
      yield* damper.onShutdown(damper.writeAllNow([{ address: 2000, value: 0 }]));
    • Collects a group as one reader and returns values in the requested order.

      Parameters

      • addresses: readonly number[]

        Register addresses, in result order.

      Returns Effect<readonly number[], ModbusError>

      Register values in the requested order, or a Modbus error.

    • Adds a group and flushes collected reads immediately.

      Parameters

      • addresses: readonly number[]

        Register addresses, in result order.

      Returns Effect<readonly number[], ModbusError>

      Register values in the requested order, or a Modbus error.