ExIEC61850 (ex_iec61850 v0.1.0)

Copy Markdown View Source

Pure Elixir implementation of the IEC 61850 protocol stack.

This top-level module provides ergonomic entrypoints for the most common client, server, control, and model-parsing workflows while delegating to the full layered protocol stack under ExIEC61850.*.

Quick Start

# Start an IED server from an SCL (.icd/.cid/.scd) or .cfg file, or an %IedModel{}
{:ok, server} = ExIEC61850.start_server("tools/model_generator/sample_model.icd", port: 10102)

# Connect a client (with optional :tls, :password, :name, :closed_handler)
{:ok, conn} = ExIEC61850.connect("127.0.0.1", 10102)
{:ok, lds} = ExIEC61850.logical_devices(conn)
{:ok, val} = ExIEC61850.read(conn, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", :mx)
:ok = ExIEC61850.disconnect(conn)
:ok = ExIEC61850.stop_server(server)

Summary

Functions

Creates and connects an IEC 61850 client to host:port.

Closes an active client connection.

Lists Logical Devices exposed by the connected IED server.

Executes a direct or SBOw Operate command on a controllable DataObject (e.g. LD/XCBR1.Pos).

Parses a .cfg model file into an %IedModel{}.

Parses an SCL (.icd/.cid/.scd) file into an %IedModel{}.

Reads an IEC 61850 object/attribute reference with the given Functional Constraint.

Creates an %IedServerConfig{} struct.

Starts a supervisor-friendly auto-reconnecting client worker (ReconnectWorker).

Starts an IEC 61850 server from an %IedModel{} or an SCL (.icd/.cid/.scd) / .cfg file path.

Stops a running IEC 61850 server.

Updates a server attribute value using a native Elixir value or %MmsValue{}.

Returns the current ExIEC61850 package version string.

Writes a native Elixir value or %MmsValue{} to an IEC 61850 attribute reference.

Functions

connect(host, port \\ 102, opts \\ [])

@spec connect(String.t(), :inet.port_number(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Creates and connects an IEC 61850 client to host:port.

Options

  • :tls - Erlang :ssl client options list (enables TLS)
  • :password - ACSE password string for authentication
  • :name - Optional GenServer process registration name
  • :closed_handler - fn reason -> ... end invoked on passive disconnect

disconnect(conn)

@spec disconnect(GenServer.server()) :: :ok

Closes an active client connection.

logical_devices(conn)

@spec logical_devices(GenServer.server()) :: {:ok, [String.t()]} | {:error, term()}

Lists Logical Devices exposed by the connected IED server.

operate(conn, do_ref, value)

@spec operate(GenServer.server(), String.t(), term()) :: :ok | {:error, term()}

Executes a direct or SBOw Operate command on a controllable DataObject (e.g. LD/XCBR1.Pos).

parse_cfg(path)

@spec parse_cfg(Path.t()) ::
  {:ok, ExIEC61850.IEC61850.Server.Model.IedModel.t()} | {:error, term()}

Parses a .cfg model file into an %IedModel{}.

parse_scl(path)

@spec parse_scl(Path.t()) ::
  {:ok, ExIEC61850.IEC61850.Server.Model.IedModel.t()} | {:error, term()}

Parses an SCL (.icd/.cid/.scd) file into an %IedModel{}.

read(conn, ref, fc)

@spec read(GenServer.server(), String.t(), atom()) ::
  {:ok, ExIEC61850.Mms.IsoMms.Common.MmsValue.t()} | {:error, term()}

Reads an IEC 61850 object/attribute reference with the given Functional Constraint.

server_config(opts \\ [])

Creates an %IedServerConfig{} struct.

start_reconnect_client(opts)

@spec start_reconnect_client(keyword()) :: GenServer.on_start()

Starts a supervisor-friendly auto-reconnecting client worker (ReconnectWorker).

start_server(model_or_path, opts \\ [])

@spec start_server(
  ExIEC61850.IEC61850.Server.Model.IedModel.t() | Path.t(),
  keyword()
) ::
  {:ok, pid()} | {:error, term()}

Starts an IEC 61850 server from an %IedModel{} or an SCL (.icd/.cid/.scd) / .cfg file path.

Options

  • :port - TCP/TLS listening port (default 102)
  • :config - Optional %IedServerConfig{} struct
  • :tls / :tls_options - Erlang :ssl server options list
  • :authenticator - fn password -> boolean() end or {mod, fun, args}
  • :file_root - Root directory for MMS file service
  • :name - Optional GenServer process registration name

stop_server(server)

@spec stop_server(GenServer.server()) :: :ok

Stops a running IEC 61850 server.

update_value(server, ref, value)

@spec update_value(GenServer.server(), String.t(), term()) :: :ok

Updates a server attribute value using a native Elixir value or %MmsValue{}.

version()

@spec version() :: String.t()

Returns the current ExIEC61850 package version string.

write(conn, ref, fc, value)

@spec write(GenServer.server(), String.t(), atom(), term()) :: :ok | {:error, term()}

Writes a native Elixir value or %MmsValue{} to an IEC 61850 attribute reference.