# `AVModbus.RTU`
[🔗](https://github.com/piyopiyoex/avmodbus/blob/v0.1.0/lib/avmodbus/rtu.ex#L1)

Modbus RTU framing、CRC validation、stream extraction を提供します。

known function は response length から frame boundary を決め、CRC で確認します。
leading noise や invalid byte は skip して次の valid frame へ再同期できます。

# `complete_silence_request`

```elixir
@spec complete_silence_request(binary()) :: {:ok, binary()} | {:error, term()}
```

silence-delimited request を検証し、可能な場合は leading noise を skip して再同期します。

# `complete_silence_response`

```elixir
@spec complete_silence_response(binary(), 1..247, AVModbus.PDU.request()) ::
  {:ok, binary()} | {:error, term()}
```

silence-delimited response を検証し、可能な場合は leading noise を skip して再同期します。

# `decode`

```elixir
@spec decode(binary()) :: {:ok, 0..247, binary()} | {:error, term()}
```

# `encode`

```elixir
@spec encode(0..247, binary()) :: {:ok, binary()} | {:error, term()}
```

# `frame_gap_us`

```elixir
@spec frame_gap_us(pos_integer()) :: pos_integer()
```

推奨される RTU inter-frame gap を microsecond で返します。

19,200 baud 以下では 11-bit character の 3.5 倍、より高速では fixed 1.75 ms を使います。

# `split_request`

```elixir
@spec split_request(binary()) ::
  {:ok, binary(), binary()} | :more | :unknown | :skip | :overflow
```

byte stream の先頭から Modbus request frame を取り出します。

known request は function-specific な PDU shape から length を求めます。
undefined function や variable-length request は silent interval で完了するまで `:unknown` を返します。

# `split_response`

```elixir
@spec split_response(binary(), 1..247, AVModbus.PDU.request()) ::
  {:ok, binary(), binary()} | :more | :unknown | :skip | :overflow
```

byte stream の先頭から response frame を取り出します。

先頭 byte が期待する response の開始になれない場合は `:skip` を返します。
caller は 1 byte 捨てて再試行し、後続の valid frame を保持できます。

---

*Consult [api-reference.md](api-reference.md) for complete listing*
