View Source Modbuzz (Modbuzz v0.1.3)

Documentation for Modbuzz.

Summary

Functions

Delete request response pair from data server.

Dump data from data server.

Start data server.

Upsert request response/callback pair to data server.

Types

@type callback() :: (request() -> response())
@type client() :: GenServer.name()
@type data_server() :: GenServer.name()
@type error() :: Modbuzz.PDU.Protocol.t()
@type request() :: Modbuzz.PDU.Protocol.t()
@type response() :: Modbuzz.PDU.Protocol.t()
@type server() :: GenServer.name()
@type unit_id() :: 0..247

Functions

Link to this function

delete(name, unit_id \\ 0, request)

View Source
@spec delete(name :: data_server(), unit_id(), request()) :: :ok

Delete request response pair from data server.

Link to this function

dump(name, unit_id \\ 0)

View Source
@spec dump(name :: data_server(), unit_id()) :: map()

Dump data from data server.

Link to this function

request(name, unit_id \\ 0, request, timeout \\ 5000)

View Source
@spec request(
  name :: client() | data_server(),
  unit_id(),
  request(),
  non_neg_integer()
) ::
  {:ok, response()} | {:error, error()} | {:error, reason :: term()}

Request data.

@spec start_data_server(name :: data_server()) :: :ok

Start data server.

Examples

iex> :ok = Modbuzz.start_data_server(:data_server)
iex> alias Modbuzz.PDU.WriteSingleCoil
iex> req = %WriteSingleCoil.Req{output_address: 0 , output_value: true}
iex> res = %WriteSingleCoil.Res{output_address: 0 , output_value: true}
iex> :ok = Modbuzz.upsert(:data_server, req, res)
iex> {:ok, ^res} = Modbuzz.request(:data_server, req)
Link to this function

start_tcp_client(name, address, port)

View Source
@spec start_tcp_client(
  name :: client(),
  address :: :inet.socket_address() | :inet.hostname(),
  port :: :inet.port_number()
) :: :ok | {:error, :already_started}

Start TCP client.

Examples

iex> :ok = Modbuzz.start_tcp_client(:client, {127, 0, 0, 1}, 50200)
iex> alias Modbuzz.PDU.WriteSingleCoil
iex> req = %WriteSingleCoil.Req{output_address: 0 , output_value: true}
iex> {:error, %WriteSingleCoil.Err{}} = Modbuzz.request(:client, req)
Link to this function

start_tcp_server(name, address, port, data_source)

View Source
@spec start_tcp_server(
  name :: server(),
  address :: :inet.socket_address() | :inet.hostname(),
  port :: :inet.port_number(),
  data_source :: data_server() | client()
) :: :ok | {:error, :already_started}

Start TCP server.

Examples

iex> :ok = Modbuzz.start_data_server(:data_server)
iex> alias Modbuzz.PDU.WriteSingleCoil
iex> req = %WriteSingleCoil.Req{output_address: 0 , output_value: true}
iex> res = %WriteSingleCoil.Res{output_address: 0 , output_value: true}
iex> :ok = Modbuzz.upsert(:data_server, req, res)
iex> :ok = Modbuzz.start_tcp_server(:server, {127, 0, 0, 1}, 50200, :data_server)
Link to this function

upsert(name, unit_id \\ 0, request, res_or_cb)

View Source
@spec upsert(name :: data_server(), unit_id(), request(), response() | callback()) ::
  :ok

Upsert request response/callback pair to data server.

When using a callback, the user is responsible for the callback. This library does not handle its error. In case of an error, the request will simply time out with noreply.