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

      @flux-control/effect-modbus-rs

      @flux-control/effect-modbus-rs

      Type-safe Modbus communication via Effect-TS, wrapping the modbus-rs npm bindings (Rust napi-rs under the hood).

      Run a server layer with Layer.launch and execute with a runtime:

      Layer.launch(tcpServerLayer({ host: "0.0.0.0", port: 502, unitId: 1 }, handlers)).pipe(Effect.runPromise)
      

      All Modbus operations fail with a ModbusError discriminated union. Use Effect.catchTags to handle specific variants:

      Effect.catchTags(effect, {
      ModbusTimeoutError: ...,
      ModbusTransportError: ...,
      })

      Nothing retries or reconnects implicitly — a transport behaves exactly as it always has until a policy is attached, so timing stays predictable by default. Resilience is configured on the transport, which owns it for every client derived from it:

      TcpTransportService.Default({
      host, port,
      retry: RetryPolicies.tcp(), // applied to every operation
      reconnect: {}, // supervised reconnect + circuit breaker
      })

      Policies are error-aware: transient failures (timeouts, framing errors, a busy device) back off exponentially with jitter (on by default), while deterministic ones (illegal address, invalid argument) fail immediately.

      Override per client — one bus, several device types — or per operation. Both replace the policy rather than composing with it:

      const meter = yield* transport.withClient(1, { retry: RetryPolicies.serial() });
      yield* meter.withRetry(RetryPolicies.none()).writeSingleCoil({ address: 0, value });

      With reconnect enabled, the transport runs one supervised reconnect for the whole application and refuses operations with ModbusCircuitOpenError while the link is down, instead of letting every caller queue requests onto a dead bus. Watch ConnectionState via transport.connectionState.

      retryModbus remains for retrying a compound operation — a read-modify-write driven as a unit — over a RetryPolicies.none() client. Note that it wraps rather than replaces: unlike the two overrides above, it is piped around an effect the client has already wrapped in its own retry, so over a policied client the two nest and attempt counts multiply.

      Resilience lives at this layer and only at this layer. modbus-rs's own transport-level retryAttempts / retryDelayMs / retryBackoffStrategy are not accepted by any transport constructor here: they retry beneath the Effect boundary where neither the policy, the circuit breaker, nor the logs can see them, and they reconnect inline, racing the supervisor fiber that owns reconnection. See UpstreamRetryOptionKey.

      AsciiTransportService
      ModbusCircuitOpenError
      ModbusConnectionClosedError
      ModbusExceptionError
      ModbusInternalError
      ModbusInvalidArgumentError
      ModbusNotConnectedError
      ModbusTimeoutError
      ModbusTransportError
      RtuTransportService
      SerialTransportService
      TcpTransportService
      WasmAsciiTransportService
      WasmRtuTransportService
      WasmSerialTransportService
      WasmWsTransportService
      EffectModbusClient
      ModbusOperations
      ModbusRetryPolicy
      ModbusRetryPolicyOptions
      ReconnectOptions
      RetryDelayOptions
      TransportResilienceOptions
      AsciiTransportOpenOptions
      CoilDefinition
      CoilDefinition
      ConnectionState
      DiscreteInputDefinition
      DiscreteInputDefinition
      ModbusError
      ModbusErrorTag
      RegisterDefinition
      RegisterDefinition
      RetryErrorOptions
      RtuTransportOpenOptions
      SlaveDeviceDefinition
      SlaveDeviceDefinition
      SlaveDeviceDefinitions
      SlaveDeviceDefinitions
      TcpTransportOpenOptions
      UpstreamRetryOptionKey
      WasmAsciiTransportOpenOptions
      WasmRtuTransportOpenOptions
      WithoutUpstreamRetry
      ConnectionState
      retryableExceptionCodes
      RetryPolicies
      makeRetryPolicy
      requestSerialPort
      retryModbus
      serialAsciiServerLayer
      serialRtuServerLayer
      tcpGatewayLayer
      tcpServerLayer
      toModbusError
      wasmSerialAsciiServerLayer
      wasmSerialRtuServerLayer
      wasmWsServerLayer