AVModbus.ASCII (avmodbus v0.1.0)

Copy Markdown View Source

Modbus ASCII の framing、LRC validation、stream extraction を提供します。

binary の各 byte を 2 文字の hexadecimal で表し、: から CR + delimiter までを 1 frame として扱います。Change ASCII Input Delimiter 用に custom delimiter も指定できます。

Summary

Functions

完全な Modbus ASCII frame を decode し、LRC を検証します。

unit id と PDU を完全な Modbus ASCII frame に encode します。

data の Modbus LRC (Longitudinal Redundancy Check) を返します。

stream buffer の先頭から 1 frame を取り出します。

Functions

decode(frame)

@spec decode(binary()) ::
  {:ok, 0..247, binary()} | {:error, :invalid_lrc | :invalid_frame}

完全な Modbus ASCII frame を decode し、LRC を検証します。

encode(unit_id, pdu, delimiter \\ 10)

@spec encode(0..247, binary(), byte()) :: {:ok, binary()} | {:error, term()}

unit id と PDU を完全な Modbus ASCII frame に encode します。

lrc(data)

@spec lrc(binary()) :: byte()

data の Modbus LRC (Longitudinal Redundancy Check) を返します。

split(buffer, delimiter \\ 10)

@spec split(binary(), byte()) :: {:ok, binary(), binary()} | {:skip, binary()} | :more

stream buffer の先頭から 1 frame を取り出します。

{:ok, frame, rest}、:more、{:skip, rest} のいずれかを返します。 incomplete frame 内で新しい : を検出した場合は、そこから次の frame として再同期します。