Modbux.Rtu.Master (Modbux v0.3.14)
View SourceAPI for a Modbus RTU Master device.
Summary
Functions
Returns a specification to start this module under a supervisor.
Close the Master serial port.
Configure the Master serial port.
Callback implementation for GenServer.init/1
.
Open the Master serial port.
Read and parse the last request (if the last request timeouts).
Send a request to Modbus RTU Slave.
Starts a Modbus RTU Master process.
Gets the Master state.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Close the Master serial port.
Configure the Master serial port.
The following options are available:
tty
- defines the serial port to spawn the Master.timeout
- defines slave timeout.active
- (true
orfalse
) specifies whether data is received as messages (mailbox) or by callingrequest/2
.gen_opts
- defines extra options for the Genserver OTP configuration.uart_opts
- defines extra options for the UART configuration.
Callback implementation for GenServer.init/1
.
Open the Master serial port.
Read and parse the last request (if the last request timeouts).
@spec request(atom() | pid() | {atom(), any()} | {:via, atom(), any()}, tuple()) :: :ok | {:ok, list()} | {:error, String.t()}
Send a request to Modbus RTU Slave.
cmd
is one of:
{:rc, slave, address, count}
readcount
coils.{:ri, slave, address, count}
readcount
inputs.{:rhr, slave, address, count}
readcount
holding registers.{:rir, slave, address, count}
readcount
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.
Starts a Modbus RTU Master process.
The following options are available:
tty
- defines the serial port to spawn the Master.timeout
- defines slave timeout.active
- (true
orfalse
) specifies whether data is received as messages (mailbox) or by callingrequest/2
.gen_opts
- defines extra options for the Genserver OTP configuration.uart_opts
- defines extra options for the UART configuration (defaults:[speed: 115200, rx_framing_timeout: 1000]).
The messages (when active mode is true) have the following form:
{:modbus_rtu, {:slave_response, cmd, values}}
or
{:modbus_rtu, {:slave_error, payload, reason}}
The following are some reasons:
:ecrc
- corrupted message (invalid crc).:einval
- invalid function.:eaddr
- invalid memory address requested.
Example
Modbux.Rtu.Master.start_link(tty: "tnt0", active: true, uart_opts: [speed: 9600])
Gets the Master state.