modbuspp  1.1.40
C++ wrapper for the libmodbus library
Modbus::Data< T, e > Class Template Reference

Arithmetic data in multiple 16-bit Modbus registers. More...

#include <data.h>

Public Member Functions

 Data ()
 Default constructor. More...
 
 Data (const T &t)
 Constructor from a value of T.
 
Endian endianness () const
 Return the bytes and words endianness.
 
T * operator & ()
 Overload of the pointer operator on the T value.
 
const T * operator & () const
 
 operator const T & () const
 
 operator T & ()
 Overload of the reference operator on the T value.
 
T & operator= (const T &t)
 Overload of the assignment operator from a T value.
 
void print ()
 Prints the hexadecimal values of the current T value. More...
 
std::array< uint16_t, sizeof(T)/2 > & registers ()
 Array of Modbus registers corresponding to the T value.
 
const std::array< uint16_t, sizeof(T)/2 > & registers () const
 Array of Modbus registers corresponding to the T value.
 
void setEndianness (Endian endian)
 Set the bytes and words endianness.
 
std::size_t size () const
 Number of bytes of type T.
 
void swap (T &v)
 Swap bytes and words of a T value v. More...
 
T & value ()
 Access to the T value.
 
const T & value () const
 

Static Public Member Functions

static void print (const uint8_t *p, const size_t s)
 Prints the hexadecimal values of a byte array. More...
 
static void print (const T &v)
 Prints the hexadecimal values of T value. More...
 

Detailed Description

template<typename T, Endian e = EndianBig>
class Modbus::Data< T, e >

Arithmetic data in multiple 16-bit Modbus registers.

Data is a template class for storing, transmitting, and receiving arithmetic data in multiple 16-bit Modbus registers.

Parameters
Tis a type of arithmetic data (int, float ...) of a size greater than or equal to 2.
eis the order of bytes and words in the data model used by the user's Modbus network. By default it is the big endian order for bytes and words that is used.
Examples:
master/read-holding-data/main.cpp, master/rw-holding-json/main.cpp, master/write-holding-data/main.cpp, server/clock-server-json/main.cpp, and server/clock-server/main.cpp.

Constructor & Destructor Documentation

◆ Data()

template<typename T, Endian e = EndianBig>
Modbus::Data< T, e >::Data ( )
inline

Default constructor.

The default value of T is 0.

Member Function Documentation

◆ operator &()

template<typename T, Endian e = EndianBig>
const T* Modbus::Data< T, e >::operator& ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator const T &()

template<typename T, Endian e = EndianBig>
Modbus::Data< T, e >::operator const T & ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ print() [1/3]

template<typename T, Endian e = EndianBig>
static void Modbus::Data< T, e >::print ( const uint8_t *  p,
const size_t  s 
)
inlinestatic

Prints the hexadecimal values of a byte array.

For debugging purpose.

◆ print() [2/3]

template<typename T, Endian e = EndianBig>
static void Modbus::Data< T, e >::print ( const T &  v)
inlinestatic

Prints the hexadecimal values of T value.

For debugging purpose.

References Modbus::Data< T, e >::print().

Here is the call graph for this function:

◆ print() [3/3]

template<typename T, Endian e = EndianBig>
void Modbus::Data< T, e >::print ( )
inline

Prints the hexadecimal values of the current T value.

For debugging purpose.

References Modbus::Data< T, e >::size(), and Modbus::Data< T, e >::swap().

Referenced by Modbus::Data< T, e >::print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap()

template<typename T, Endian e = EndianBig>
void Modbus::Data< T, e >::swap ( T &  v)
inline

Swap bytes and words of a T value v.

The order used is endianness().

References Modbus::EndianBigBig, Modbus::EndianBigLittle, Modbus::EndianLittleBig, and Modbus::EndianLittleLittle.

Referenced by Modbus::Data< T, e >::print().

Here is the caller graph for this function:

◆ value()

template<typename T, Endian e = EndianBig>
const T& Modbus::Data< T, e >::value ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.