ExDlt645.Slave (ex_dlt645 v0.1.0)

Copy Markdown View Source

DL/T 645-2007 Slave (Electricity Meter Simulator) GenServer.

Simulates an actual electricity meter responding to DL/T 645 master requests over physical serial ports, in-memory virtual buses, or TCP sockets.

Maintains internal registers/state for energy, voltage, current, power, parameters, and responds automatically to standard DL/T 645 function codes.

Summary

Functions

Returns the meter's current communication address.

Returns a specification to start this module under a supervisor.

Retrieves the value for a given Data Identifier from the meter's internal state.

Updates the meter's communication address.

Sets the value for a given Data Identifier in the meter's internal state.

Starts a DL/T 645 Slave GenServer.

Stops the Slave GenServer process.

Types

slave_ref()

@type slave_ref() :: pid() | atom()

Functions

address(pid)

@spec address(slave_ref()) :: String.t()

Returns the meter's current communication address.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_value(pid, di)

@spec get_value(slave_ref(), non_neg_integer() | binary() | String.t()) ::
  {:ok, term()} | :error

Retrieves the value for a given Data Identifier from the meter's internal state.

set_address(pid, new_address)

@spec set_address(slave_ref(), String.t()) :: :ok

Updates the meter's communication address.

set_value(pid, di, value)

@spec set_value(slave_ref(), non_neg_integer() | binary() | String.t(), term()) :: :ok

Sets the value for a given Data Identifier in the meter's internal state.

start_link(params, gen_opts \\ [])

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

Starts a DL/T 645 Slave GenServer.

Parameters

  • :address - 12-digit meter address string (e.g. "123456789012").
  • :tty - Serial device or virtual bus (e.g. "virtual").
  • :transport - Optional explicit Transport module.
  • :data - Map of initial data items %{di => value}.

stop(pid)

@spec stop(slave_ref()) :: :ok

Stops the Slave GenServer process.