Modbus library

Index:

Functions:

modbus-connect

modbus-connect

Synopsis
Creates a master modbus server and connects to it.
Usage
(modbus-connect
  "host" => host
  "port" => port
  "keep-alive" => keep_alive
)
Returns
mid
Where
  • host is string[0..1]: The IP address of the modbus host. 127.0.0.1 by default.
  • port is number[0..1]: The TCP port of the modbus host. 502 by default.
  • keep_alive is boolean[0..1]: A boolean indicating if connection must be keeping alive.
  • mid is string: The modbus master identifier to use in other modbus functions.
Description
This function creates a master modbus server with the specified parameters (host, port and keep_alive) and connects to it to allow further read operations on the slave modbus devices.
Examples
(set mid
  (modbus-connect
    "host" => "10.70.2.70"
    "keep-alive" => true
  )
)
"109afd7c87634705b2e627cf8c7d51de"
modbus-disconnect

modbus-disconnect

Synopsis
Disconnects and destroys a master modbus server.
Usage
(modbus-disconnect mid)
Returns
result
Where
  • mid is string: The modbus master identifier.
  • result is string: the word 'disconnected' if disconnection was successfull. Otherwise an exception will be thrown.
Description
This function disconnects and destroys the master modbus server identified by the specified mid parameter.
Examples
(modbus-disconnect
  "109afd7c87634705b2e627cf8c7d51de"
)
"disconnected"
modbus-read

modbus-read

Synopsis
Read registers from a modbus slave device.
Usage
(modbus-read
  mid
  "registers" => registers
  "server" => server
  "address" => address
  "quantity" => quantity
)
Returns
result
Where
  • mid is string: The modbus master identifier.
  • registers is string[0..1]: The type of registers to read: holding, input, coils or discrete. Its default value is holding.
  • server is number[0..1]: The address of the modbus slave device. 1 by default.
  • address is number[0..1]: The address of the first register to read. 0 by default.
  • quantity is number[0..1]: The number of registers to read starting from address.
Description
Returns a list that contains the values of the registers of the specified modbus slave device.
Examples
(modbus-read
  mid
  "registers" => "holding"
  "server" => 2
  "address" => 12087
  "quantity" => 5
)
(45 0 12 3 0)
Top