modbuspp  1.1.40
C++ wrapper for the libmodbus library
Modbus::NetLayer Class Reference

Network layer base class (backend) More...

#include <netlayer.h>

Inheritance diagram for Modbus::NetLayer:
Inheritance graph

Public Member Functions

const std::string & connection () const
 Returns the connection used. More...
 
modbus_t * context ()
 libmodbus context More...
 
const modbus_t * context () const
 
uint16_t maxAduLength () const
 Returns the maximum ADU length.
 
Net net () const
 Underlying layer used (backend) More...
 
 NetLayer ()
 Constructor.
 
virtual bool prepareToSend (Message &msg)
 Prepare the message msg before sending. More...
 
virtual int sendRawMessage (const Message *msg)
 Send a request/response msg via the socket of the context() More...
 
const std::string & settings () const
 Returns the connection settings. More...
 
virtual ~NetLayer ()
 Destructor.
 

Static Public Member Functions

static bool checkMessage (const Message &msg)
 Return true if the message is valid for this backend.
 
static std::string lastError ()
 last error message More...
 

Detailed Description

Network layer base class (backend)

Author
Pascal JEAN, aka epsilonrt

Member Function Documentation

◆ connection()

const std::string& Modbus::NetLayer::connection ( ) const

Returns the connection used.

Serial port or host depending on the backend.

◆ context() [1/2]

modbus_t* Modbus::NetLayer::context ( )

libmodbus context

context is an opaque structure containing all necessary information to establish a connection with other Modbus devices according to the selected variant.

◆ context() [2/2]

const modbus_t* Modbus::NetLayer::context ( ) const

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

◆ lastError()

static std::string Modbus::NetLayer::lastError ( )
static

last error message

This function shall return the error message corresponding to the last error. This function must be called right after the instruction that triggered an error.

◆ net()

Net Modbus::NetLayer::net ( ) const

Underlying layer used (backend)

This function allows to know the underlying layer used.

◆ prepareToSend()

virtual bool Modbus::NetLayer::prepareToSend ( Message msg)
virtual

Prepare the message msg before sending.

This function updates the ADU header or adds the CRC at the end depending on the network used..

Reimplemented in Modbus::RtuLayer, and Modbus::TcpLayer.

◆ sendRawMessage()

virtual int Modbus::NetLayer::sendRawMessage ( const Message msg)
virtual

Send a request/response msg via the socket of the context()

This function can be used to send message not handled by the library. The message is transmitted "raw", without any modification.

Returns
The function shall return the full message length, if successful. Otherwise it shall return -1 and set errno.

Reimplemented in Modbus::RtuLayer, and Modbus::TcpLayer.

◆ settings()

const std::string& Modbus::NetLayer::settings ( ) const

Returns the connection settings.

IP port or speed, parity and stop bit depending on the backend