Modbuv.Tcp (modbuv v0.1.0)

Copy Markdown View Source

Modbus TCP ADU framing: MBAP header plus the Codec PDU.

Summary

Functions

Encodes a Modbus exception response into a TCP ADU for the given slave, function code, reason, and transaction ID.

Packs a Modbus TCP request ADU (MBAP header + PDU). transid is the transaction identifier (0–65535).

Encodes a frame tuple and its response values into a Modbus TCP response ADU using the given transaction ID.

Parses a Modbus TCP request ADU binary using the given fc_map. Returns {:ok, frame, transid} on success or {:error, reason, fc} on failure.

Functions

pack_exception(slave, fc, reason, transid)

@spec pack_exception(0..255, 1..127, atom(), 0..65535) :: binary()

Encodes a Modbus exception response into a TCP ADU for the given slave, function code, reason, and transaction ID.

pack_req(frame, transid)

@spec pack_req(tuple(), 0..65535) :: binary()

Packs a Modbus TCP request ADU (MBAP header + PDU). transid is the transaction identifier (0–65535).

pack_res(frame, values, transid)

@spec pack_res(tuple(), list() | nil, 0..65535) :: binary()

Encodes a frame tuple and its response values into a Modbus TCP response ADU using the given transaction ID.

parse_req(arg1, fc_map)

@spec parse_req(binary(), map()) ::
  {:ok, tuple(), 0..65535} | {:error, atom(), integer() | nil}

Parses a Modbus TCP request ADU binary using the given fc_map. Returns {:ok, frame, transid} on success or {:error, reason, fc} on failure.

parse_res(frame, arg2)

@spec parse_res(tuple(), binary()) :: list() | nil | {:error, term()}

split_adus(data)

@spec split_adus(binary()) :: {[binary()], binary()}