# `Modbuv.Rtu.Master`
[🔗](https://github.com/ultra0224/modbuv/blob/v0.1.0/lib/modbuv/rtu/master.ex#L1)

Modbus RTU master. Reads raw UART bytes and frames replies from the request
currently in flight. Only one request may be in flight at a time.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `close`

```elixir
@spec close(pid()) :: :ok
```

Closes the UART port. Returns `:ok` and clears any pending command.

# `configure`

```elixir
@spec configure(pid(), keyword()) :: :ok
```

Updates the master's connection parameters (`:tty`, `:active`, `:timeout`, `:uart_opts`) at runtime, reopening the UART port.

# `open`

```elixir
@spec open(pid()) :: :ok
```

Opens the UART port for the configured TTY device.

# `read`

```elixir
@spec read(pid()) :: nil | :ok | {:ok, list()} | {:error, term()}
```

Re-reads the UART for the last sent command in passive mode. Returns `nil` if no command has been sent yet, or `:error` in active mode.

# `request`

```elixir
@spec request(pid(), tuple()) :: :ok | {:ok, list()} | {:error, term()}
```

Packs and sends a Modbus frame over RTU. In passive mode blocks until the slave responds; in active mode returns `:ok` and delivers the result to `parent_pid`.

# `start_link`

```elixir
@spec start_link(keyword(), keyword()) :: {:ok, pid()} | {:error, term()}
```

Starts the RTU master GenServer. `params` must include `:tty` and may include `:active`, `:timeout`, and `:uart_opts`.

# `state`

```elixir
@spec state(pid()) :: %Modbuv.Rtu.Master{
  active: term(),
  cmd: term(),
  last_cmd: term(),
  parent_pid: term(),
  status: term(),
  timeout: term(),
  tty: term(),
  uart_opts: term(),
  uart_pid: term()
}
```

Returns the current internal state struct of the RTU master.

# `stop`

```elixir
@spec stop(pid()) :: :ok
```

Stops the RTU master GenServer process.

---

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