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

TCP/IP v4 & v6 network layer. More...

#include <tcplayer.h>

Inheritance diagram for Modbus::TcpLayer:
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...
 
const std::string & node () const
 Host name or IP address. More...
 
virtual bool prepareToSend (Message &msg)
 
virtual int sendRawMessage (const Message *msg)
 
const std::string & service () const
 Service name or port number. More...
 
const std::string & settings () const
 Returns the connection settings. More...
 
 TcpLayer (const std::string &host, const std::string &service)
 Constructor.
 

Static Public Member Functions

static bool checkMessage (const Message &msg)
 
static std::string lastError ()
 last error message More...
 

Detailed Description

TCP/IP v4 & v6 network layer.

This class can not and should not be instantiated by the user. It provides access to properties and methods specific to the TCP layer.

An instance of this class is created by the constructor Device::Device() of the Device class (or its derived classes) if the TCP layer is selected.

Access to this instance is done using the Device::tcp() method.

Author
Pascal JEAN, aka epsilonrt
See also
Device::Device()
Device::tcp()

Member Function Documentation

◆ checkMessage()

static bool Modbus::TcpLayer::checkMessage ( const Message msg)
static

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

◆ connection()

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

Returns the connection used.

Serial port or host depending on the backend.

◆ context() [1/2]

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

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
inherited

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 ( )
staticinherited

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
inherited

Underlying layer used (backend)

This function allows to know the underlying layer used.

◆ node()

const std::string& Modbus::TcpLayer::node ( ) const

Host name or IP address.

This property specifies the host name or IP address of the host to which we are connected, eg. "192.168.0.5" , "::1" or "server.com".

◆ prepareToSend()

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

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

Reimplemented from Modbus::NetLayer.

◆ sendRawMessage()

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

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

Reimplemented from Modbus::NetLayer.

◆ service()

const std::string& Modbus::TcpLayer::service ( ) const

Service name or port number.

This property is the service name/port number to which we are connected.

◆ settings()

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

Returns the connection settings.

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