Modbus TCP client. In passive mode request/2 followed by confirmation/1
returns the result synchronously; in active mode responses are sent to
d_pid as {:modbuv_tcp, frame, result}.
Summary
Functions
Returns a specification to start this module under a supervisor.
Closes the underlying TCP socket and resets the client state. Always returns :ok.
Updates the client's connection parameters (:ip, :tcp_port, :timeout, :active, :d_pid) while the socket is closed. Returns :error if the socket is already connected.
Waits for and parses the server response for the last request/2 call in passive mode. Returns :error if used in active mode.
Opens a TCP connection to the configured host and port. Returns :ok on success or {:error, reason} on failure.
Returns and clears the map of pending active-mode messages that have not yet been matched to a response.
Sends a Modbus frame to the server. In passive mode call confirmation/1 afterward to receive the result; in active mode returns :ok immediately.
Starts the TCP client GenServer. params accepts :ip, :tcp_port, :timeout, :active, and :d_pid; gen_opts are passed to GenServer.start_link/3.
Returns the current internal state struct of the client.
Stops the client GenServer process.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec close(pid()) :: :ok
Closes the underlying TCP socket and resets the client state. Always returns :ok.
Updates the client's connection parameters (:ip, :tcp_port, :timeout, :active, :d_pid) while the socket is closed. Returns :error if the socket is already connected.
Waits for and parses the server response for the last request/2 call in passive mode. Returns :error if used in active mode.
Opens a TCP connection to the configured host and port. Returns :ok on success or {:error, reason} on failure.
Returns and clears the map of pending active-mode messages that have not yet been matched to a response.
Sends a Modbus frame to the server. In passive mode call confirmation/1 afterward to receive the result; in active mode returns :ok immediately.
Starts the TCP client GenServer. params accepts :ip, :tcp_port, :timeout, :active, and :d_pid; gen_opts are passed to GenServer.start_link/3.
@spec state(pid()) :: %Modbuv.Tcp.Client{ active: term(), buffer: term(), cmd: term(), d_pid: term(), ip: term(), pending_msg: term(), pending_started: term(), req_started_at: term(), sent_transid: term(), socket: term(), status: term(), tcp_port: term(), timeout: term(), transid: term() }
Returns the current internal state struct of the client.
@spec stop(pid()) :: :ok
Stops the client GenServer process.