Modbuv.Rtu.Master (modbuv v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

Returns a specification to start this module under a supervisor.

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

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

Opens the UART port for the configured TTY device.

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.

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.

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

Returns the current internal state struct of the RTU master.

Stops the RTU master GenServer process.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(pid)

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

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

configure(pid, params)

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

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

open(pid)

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

Opens the UART port for the configured TTY device.

read(pid)

@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(pid, frame)

@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(params, gen_opts \\ [])

@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(pid)

@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(pid)

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

Stops the RTU master GenServer process.