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

AtomVM 向けの Modbus ライブラリです。

protocol の encode / decode を AtomVM `:uart` adapter から分離しているため、
通常の BEAM runtime 上でもテストできます。RTU / ASCII client / server、
PDU codec、framing、transport-independent な server handler boundary、
sparse in-memory data model を提供します。

client と server handler は同じ result contract を共有します。device が Modbus
exception を返した場合は `{:error, {:exception, reason}}` です。

# `address`

```elixir
@type address() :: 0..65535
```

# `error`

```elixir
@type error() ::
  {:exception, exception()}
  | :timeout
  | :closed
  | :queue_full
  | {:invalid_response, binary()}
```

# `exception`

```elixir
@type exception() ::
  :illegal_function
  | :illegal_data_address
  | :illegal_data_value
  | :server_device_failure
  | :acknowledge
  | :server_device_busy
  | :memory_parity_error
  | :gateway_path_unavailable
  | :gateway_target_device_failed_to_respond
  | byte()
```

# `result`

```elixir
@type result() :: :ok | {:ok, term()} | {:error, error()}
```

# `unit_id`

```elixir
@type unit_id() :: 0..255
```

# `word`

```elixir
@type word() :: 0..65535
```

# `exception_code`

```elixir
@spec exception_code(exception()) :: byte()
```

Modbus exception 名または code を wire code へ変換します。

# `exception_name`

```elixir
@spec exception_name(byte()) :: exception()
```

Modbus exception code を既知の名前へ変換し、未知の code はそのまま返します。

---

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