ModbusSMA  v1.0.0
modbusSMA::MBConnectionBase Class Referenceabstract

Base class for the modbus connection. More...

#include <MBConnectionBase.hpp>

Inheritance diagram for modbusSMA::MBConnectionBase:
[legend]

Public Member Functions

virtual ~MBConnectionBase ()
 Disconnects the modbus connection if neccessary.
 
 MBConnectionBase (MBConnectionBase const &)=delete
 
void operator= (MBConnectionBase const &)=delete
 
ErrorCode connect ()
 Creates the modbus connection based on the backend context implementation. More...
 
ErrorCode setSlaveID (int _id)
 Sets the slave/uinit ID of the modbus connection. More...
 
void disconnect ()
 Disconnects an active modbus connnection (if present, else does nothing).
 
bool isConnected () const
 Returns whether a valid conection exists. More...
 
std::vector< uint16_t > readRegisters (uint32_t _reg, uint32_t _num)
 read _num registers from the device More...
 
modbus_t * getConnection ()
 Returns the raw connection. More...
 
virtual ConnectionType type ()=0
 Returns the modbus connection type. More...
 
virtual std::string description ()=0
 Textual description of the connection. More...
 

Protected Member Functions

virtual modbus_t * createModbusContext ()=0
 Create and return the modbus context. More...
 

Detailed Description

Base class for the modbus connection.

This class handles connecting and disconnecting the modbus interface. Recieving and sending raw data is also handled here.

The modbus context creation (IP, RTU, etc.) is handled in the subclasses.

Note
The derived classes are only responsible for creating the context. All other modbus_t context handling (including destruction) is done in this class.

Definition at line 41 of file MBConnectionBase.hpp.

Member Function Documentation

◆ connect()

ErrorCode MBConnectionBase::connect ( )

Creates the modbus connection based on the backend context implementation.

Note
A previously established connection is disconnected when calling this function.

Definition at line 33 of file MBConnectionBase.cpp.

◆ createModbusContext()

virtual modbus_t* modbusSMA::MBConnectionBase::createModbusContext ( )
protectedpure virtual

Create and return the modbus context.

Implemented in modbusSMA::MBConnectionRTU, modbusSMA::MBConnectionIP, and modbusSMA::MBConnectionIP_PI.

◆ description()

virtual std::string modbusSMA::MBConnectionBase::description ( )
pure virtual

Textual description of the connection.

Implemented in modbusSMA::MBConnectionRTU, modbusSMA::MBConnectionIP, and modbusSMA::MBConnectionIP_PI.

◆ getConnection()

modbus_t* modbusSMA::MBConnectionBase::getConnection ( )
inline

Returns the raw connection.

DO NOT close OR free it.

Definition at line 62 of file MBConnectionBase.hpp.

◆ isConnected()

bool modbusSMA::MBConnectionBase::isConnected ( ) const
inline

Returns whether a valid conection exists.

Definition at line 58 of file MBConnectionBase.hpp.

◆ readRegisters()

vector< uint16_t > MBConnectionBase::readRegisters ( uint32_t  _reg,
uint32_t  _num 
)

read _num registers from the device

The maximum number of registers is limited by SMA_MODBUS_MAX_REGISTER_COUNT

Parameters
_regThe starting register
_numThe number of registers to read
Returns
A vector of the result OR an empty vector on error

Definition at line 72 of file MBConnectionBase.cpp.

◆ setSlaveID()

ErrorCode MBConnectionBase::setSlaveID ( int  _id)

Sets the slave/uinit ID of the modbus connection.

Returns
ErrorCode::OK on success ErrorCode::INVALID_STATE if not connected ErrorCode::ERROR when setting the id failed

Definition at line 100 of file MBConnectionBase.cpp.

◆ type()

virtual ConnectionType modbusSMA::MBConnectionBase::type ( )
pure virtual

Returns the modbus connection type.

Implemented in modbusSMA::MBConnectionRTU, modbusSMA::MBConnectionIP, and modbusSMA::MBConnectionIP_PI.


The documentation for this class was generated from the following files: