modbuspp
1.1.40
C++ wrapper for the libmodbus library
|
Slave connected to Modbus. More...
#include <slave.h>
Public Member Functions | |
int | dataAddress (int addr) const |
returns the address in the MODBUS data model corresponding to a PDU address. More... | |
Device * | device () const |
returns the device used to access the network | |
bool | isOpen () const |
returns true if isValid() and device() is opened. | |
bool | isValid () const |
returns true if device() and number() are sets | |
int | number () const |
Get slave number. More... | |
int | pduAddress (int addr) const |
returns the PDU address corresponding to an address in the MODBUS data model. More... | |
bool | pduAddressing () const |
Modbus addressing mode. More... | |
int | readCoil (int addr, bool &dest) |
Read a single coil (bit) More... | |
virtual int | readCoils (int addr, bool *dest, int nb=1) |
Read many coils (bits) More... | |
int | readDiscreteInput (int addr, bool &dest) |
Read a single discrete input (input bit) More... | |
virtual int | readDiscreteInputs (int addr, bool *dest, int nb=1) |
Read many discrete inputs (input bits) More... | |
int | readInputRegister (int addr, uint16_t &dest) |
Read a single input register. More... | |
template<typename T , Endian e> | |
int | readInputRegister (int addr, Data< T, e > &dest) |
Read a single input data. More... | |
virtual int | readInputRegisters (int addr, uint16_t *dest, int nb=1) |
Read many input registers. More... | |
template<typename T , Endian e> | |
int | readInputRegisters (int addr, Data< T, e > *dest, int nb=1) |
Read many input data. More... | |
int | readRegister (int addr, uint16_t &dest) |
Read a single register. More... | |
template<typename T , Endian e> | |
int | readRegister (int addr, Data< T, e > &dest) |
Read a single holding data. More... | |
virtual int | readRegisters (int addr, uint16_t *dest, int nb=1) |
Read many registers. More... | |
template<typename T , Endian e> | |
int | readRegisters (int addr, Data< T, e > *dest, int nb=1) |
Read many holding data. More... | |
virtual int | reportSlaveId (uint16_t max_dest, uint8_t *dest) |
returns a description of the controller More... | |
template<typename T , Endian e = EndianBig> | |
int | reportSlaveId (SlaveReport< T, e > &dest) |
returns a description of the controller More... | |
void | setDevice (Device *dev) |
Sets the device used to access the network. | |
void | setNumber (int n) |
Sets the slave number. | |
void | setPduAddressing (bool pduAddressing=true) |
Set the Modbus addressing mode. More... | |
Slave (int slaveAddr, Device *dev) | |
Constructor. | |
Slave () | |
Default Constructor. More... | |
virtual int | writeCoil (int addr, bool src) |
Write a single coil (bit) More... | |
virtual int | writeCoils (int addr, const bool *src, int nb) |
Write many coils (bits) More... | |
virtual int | writeReadRegisters (int write_addr, const uint16_t *src, int write_nb, int read_addr, uint16_t *dest, int read_nb) |
Write and read many registers in a single transaction. More... | |
virtual int | writeRegister (int addr, uint16_t value) |
Write a single register. More... | |
template<typename T , Endian e> | |
int | writeRegister (int addr, Data< T, e > &value) |
Write a single holding data. More... | |
virtual int | writeRegisters (int addr, const uint16_t *src, int nb) |
Write many registers. More... | |
template<typename T , Endian e> | |
int | writeRegisters (int addr, Data< T, e > *src, int nb=1) |
Write many holding data. More... | |
virtual | ~Slave () |
Destructor. More... | |
Static Public Member Functions | |
static void | setBoolArray (bool *dest, const uint8_t *src, size_t n) |
Set many booleans from an array of bytes. More... | |
Modbus::Slave::Slave | ( | ) |
Default Constructor.
object cannot be used without calling setDevice() and setNumber()
Referenced by reportSlaveId().
|
virtual |
Destructor.
The destructor closes the connection if it is open and releases all affected resources.
int Modbus::Slave::dataAddress | ( | int | addr | ) | const |
returns the address in the MODBUS data model corresponding to a PDU address.
If the PDU addressing mode is not enabled (which is the case by default), the data model address is equal to the PDU address plus 1, otherwise they are equal.
int Modbus::Slave::number | ( | ) | const |
Get slave number.
This function shall get the slave number.
int Modbus::Slave::pduAddress | ( | int | addr | ) | const |
returns the PDU address corresponding to an address in the MODBUS data model.
If the PDU addressing mode is not enabled (which is the case by default), the PDU address is equal to the MODBUS address minus 1, otherwise they are equal.
bool Modbus::Slave::pduAddressing | ( | ) | const |
Modbus addressing mode.
This function shall return the Modbus addressing mode used. The address mode used is, by default, that of the data model, that is to say, a numbering of the registers from 1 to n.
The Modbus application protocol defines precisely PDU addressing rules. In a Modbus PDU each data is addressed from 0 to 65535.
It also defines clearly a Modbus data model composed of 4 blocks that comprises several elements numbered from 1 to n.
In the Modbus data Model each element within a data block is numbered from 1 to n.
Afterwards the Modbus data model has to be bound to the device application (IEC -61131 object, or other application model).
|
inline |
Read a single coil (bit)
This function shall read a signle bit (coil) to the address addr of the device. The result of reading is stored in dest as boolean.
The function uses the Modbus function code 0x01 (read coil status).
References readCoils().
|
virtual |
Read many coils (bits)
This function shall read the status of the nb bits (coils) to the address addr of the remote device. The result of reading is stored in dest array as boolean.
The function uses the Modbus function code 0x01 (read coil status).
Reimplemented in Modbus::BufferedSlave.
Referenced by readCoil().
|
inline |
Read a single discrete input (input bit)
This function shall read a single input bits to the address addr of the device. The result of reading is stored in dest as boolean.
The function uses the Modbus function code 0x02 (read input status).
References readDiscreteInputs().
|
virtual |
Read many discrete inputs (input bits)
This function shall read the content of the nb input bits to the address addr of the remote device. The result of reading is stored in dest array as boolean.
The function uses the Modbus function code 0x02 (read input status).
Reimplemented in Modbus::BufferedSlave.
Referenced by readDiscreteInput().
|
inline |
Read a single input register.
This function shall read a single input register to the address addr of the device.
The result of reading is stored in dest as word values (16 bits).
The function uses the Modbus function code 0x04 (read input registers). The holding registers and input registers have different historical meaning, but nowadays it's more common to use holding registers only.
References readInputRegisters().
Referenced by Modbus::BufferedSlave::writeInputRegister().
|
inline |
Read a single input data.
Data is a template class for storing, transmitting, and receiving arithmetic data in multiple 16-bit Modbus registers.
This function shall read a single input data to the address addr of the device.
The result of reading is stored in dest as T value.
The function uses the Modbus function code 0x04 (read input registers).
References readInputRegisters(), and Modbus::Data< T, e >::registers().
|
virtual |
Read many input registers.
This function shall read the content of the nb input registers to the address addr of the remote device.
The result of reading is stored in dest array as word values (16 bits).
The function uses the Modbus function code 0x04 (read input registers). The holding registers and input registers have different historical meaning, but nowadays it's more common to use holding registers only.
Reimplemented in Modbus::BufferedSlave.
Referenced by readInputRegister(), readInputRegisters(), and Modbus::BufferedSlave::writeInputRegister().
|
inline |
Read many input data.
Data is a template class for storing, transmitting, and receiving arithmetic data in multiple 16-bit Modbus registers.
This function shall read the content of the nb input data to the address addr of the device.
The result of reading is stored in dest array as T values.
The function uses the Modbus function code 0x04 (read input registers).
References readInputRegisters().
|
inline |
Read a single register.
This function shall read a signle holding register to the address addr of the device.
The result of reading is stored in dest as word values (16 bits).
The function uses the Modbus function code 0x03 (read holding registers).
References readRegisters().
Referenced by Modbus::BufferedSlave::writeInputRegister().
|
inline |
Read a single holding data.
Data is a template class for storing, transmitting, and receiving arithmetic data in multiple 16-bit Modbus registers.
This function shall read a single holding data to the address addr of the device.
The result of reading is stored in dest as T value.
The function uses the Modbus function code 0x03 (read holding registers).
References readRegisters(), and Modbus::Data< T, e >::registers().
|
virtual |
Read many registers.
This function shall read the content of the nb holding registers to the address addr of the remote device.
The result of reading is stored in dest array as word values (16 bits).
The function uses the Modbus function code 0x03 (read holding registers).
Reimplemented in Modbus::BufferedSlave.
Referenced by readRegister(), readRegisters(), and Modbus::BufferedSlave::writeInputRegister().
|
inline |
Read many holding data.
Data is a template class for storing, transmitting, and receiving arithmetic data in multiple 16-bit Modbus registers.
This function shall read the content of the nb data to the address addr of the device.
The result of reading is stored in dest array as T values.
The function uses the Modbus function code 0x03 (read holding registers).
References readRegisters().
|
virtual |
returns a description of the controller
This function shall send a request to the controller to obtain a description of the controller.
The response stored in dest contains:
The function writes at most max_dest bytes from the response to dest so you must ensure that dest is large enough.
Reimplemented in Modbus::BufferedSlave.
Referenced by reportSlaveId(), Modbus::BufferedSlave::writeInputRegister(), and writeRegister().
|
inline |
returns a description of the controller
SlaveReport is a template class for storing and manipulate slave identifier datas returns by the MODBUS 17 function.
dest | description of the controller |
References reportSlaveId(), and Slave().
|
static |
Set many booleans from an array of bytes.
All the bits of the bytes read from the first position of the array src are written as booleans in the dest array.
dest | |
src | |
n |
Referenced by writeRegister().
void Modbus::Slave::setPduAddressing | ( | bool | pduAddressing = true | ) |
Set the Modbus addressing mode.
pduAddressing | true for Modbus PDU adressing |
|
virtual |
Write a single coil (bit)
This function shall write the status of src at the address addr of the remote device.
The function uses the Modbus function code 0x05 (force single coil).
Reimplemented in Modbus::BufferedSlave.
|
virtual |
Write many coils (bits)
This function shall write the status of the nb bits (coils) from src at the address addr of the remote device. The src array must contains booelans.
The function uses the Modbus function code 0x0F (force multiple coils).
Reimplemented in Modbus::BufferedSlave.
|
virtual |
Write and read many registers in a single transaction.
This function shall write the content of the write_nb holding registers from the array 'src' to the address write_addr of the remote device then shall read the content of the read_nb holding registers to the address read_addr of the remote device. The result of reading is stored in dest array as word values (16 bits).
You must take care to allocate enough memory to store the results in dest (at least nb * sizeof(uint16_t)).
The function uses the Modbus function code 0x17 (write/read registers).
Reimplemented in Modbus::BufferedSlave.
|
virtual |
Write a single register.
This function shall write the value of value holding registers at the address addr of the remote device.
The function uses the Modbus function code 0x06 (preset single register).
Reimplemented in Modbus::BufferedSlave.
Referenced by Modbus::BufferedSlave::writeInputRegister().
|
inline |
Write a single holding data.
Data is a template class for storing, transmitting, and receiving arithmetic data in multiple 16-bit Modbus registers.
This function shall write a single holding data from value at address addr of the device.
The function uses the Modbus function code 0x10 (preset multiple registers).
References Modbus::Data< T, e >::registers(), reportSlaveId(), setBoolArray(), and writeRegisters().
|
virtual |
Write many registers.
This function shall write the content of the nb holding registers from the array src at address addr of the remote device.
The function uses the Modbus function code 0x10 (preset multiple registers).
Reimplemented in Modbus::BufferedSlave.
Referenced by Modbus::BufferedSlave::writeInputRegister(), writeRegister(), and writeRegisters().
|
inline |
Write many holding data.
Data is a template class for storing, transmitting, and receiving arithmetic data in multiple 16-bit Modbus registers.
This function shall write the content of the nb holding data from the array src at address addr of the device.
The function uses the Modbus function code 0x10 (preset multiple registers).
References writeRegisters().