View Source Modbuzz (Modbuzz v0.1.5)
Documentation for Modbuzz
.
Summary
Functions
Delete request response pair from data server.
Dump data from data server.
Request data.
Start data server.
Start TCP client.
Start TCP server.
Upsert request response/callback pair to data server.
Types
@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
@spec delete(name :: data_server(), unit_id(), request()) :: :ok
Delete request response pair from data server.
@spec dump(name :: data_server(), unit_id()) :: map()
Dump data from data server.
@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)
@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)
@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)
@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.