Modbux.Tcp.Client (Modbux v0.3.14)

View Source

API for Modbus TCP Client.

Summary

Functions

Returns a specification to start this module under a supervisor.

Close the tcp port of the Client.

Configure the Client (status must be :closed).

In passive mode (active: false), reads the confirmation of the connected Modbux Server.

Connect the Client to a Server.

In passive mode (active: false), flushed the pending messages.

Callback implementation for GenServer.init/1.

Send a request to Modbux TCP Server.

Starts a Modbus TCP Client process.

Gets the state of the Client.

Stops the Client.

Types

client_option()

@type client_option() ::
  {:ip, {byte(), byte(), byte(), byte()}}
  | {:active, boolean()}
  | {:tcp_port, non_neg_integer()}
  | {:timeout, non_neg_integer()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(pid)

Close the tcp port of the Client.

configure(pid, params)

Configure the Client (status must be :closed).

The following options are available:

  • ip - is the internet address of the desired Modbux TCP Server.
  • tcp_port - is the Modbux TCP Server tcp port number .
  • timeout - is the connection timeout.
  • active - (true or false) specifies whether data is received as messages (mailbox) or by calling confirmation/1 each time request/2 is called.

confirmation(pid)

In passive mode (active: false), reads the confirmation of the connected Modbux Server.

connect(pid)

Connect the Client to a Server.

flush(pid)

In passive mode (active: false), flushed the pending messages.

init(args)

Callback implementation for GenServer.init/1.

request(pid, cmd)

Send a request to Modbux TCP Server.

cmd is a 4 elements tuple, as follows:

  • {:rc, slave, address, count} read count coils.
  • {:ri, slave, address, count} read count inputs.
  • {:rhr, slave, address, count} read count holding registers.
  • {:rir, slave, address, count} read count input registers.
  • {:fc, slave, address, value} force single coil.
  • {:phr, slave, address, value} preset single holding register.
  • {:fc, slave, address, values} force multiple coils.
  • {:phr, slave, address, values} preset multiple holding registers.

start_link(params, opts \\ [])

Starts a Modbus TCP Client process.

The following options are available:

  • ip - is the internet address of the desired Modbux TCP Server.
  • tcp_port - is the desired Modbux TCP Server tcp port number.
  • timeout - is the connection timeout.
  • active - (true or false) specifies whether data is received as messages (mailbox) or by calling confirmation/1 each time request/2 is called.

The messages (when active mode is true) have the following form:

{:modbus_tcp, cmd, values}

Example

Modbux.Tcp.Client.start_link(ip: {10,77,0,2}, port: 502, timeout: 2000, active: true)

state(pid)

Gets the state of the Client.

stop(pid)

Stops the Client.