# `ExDlt645.Slave`
[🔗](https://github.com/Ultraluv/ex_dlt645/blob/v0.1.0/lib/ex_dlt645/slave.ex#L1)

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.

# `slave_ref`

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

# `address`

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

Returns the meter's current communication address.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_value`

```elixir
@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`

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

Updates the meter's communication address.

# `set_value`

```elixir
@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`

```elixir
@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`

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

Stops the Slave GenServer process.

---

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