ModbusSMA
v1.0.0
|
Base class for the modbus connection. More...
#include <MBConnectionBase.hpp>
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... | |
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.
Definition at line 41 of file MBConnectionBase.hpp.
ErrorCode MBConnectionBase::connect | ( | ) |
Creates the modbus connection based on the backend context implementation.
Definition at line 33 of file MBConnectionBase.cpp.
|
protectedpure virtual |
Create and return the modbus context.
Implemented in modbusSMA::MBConnectionRTU, modbusSMA::MBConnectionIP, and modbusSMA::MBConnectionIP_PI.
|
pure virtual |
Textual description of the connection.
Implemented in modbusSMA::MBConnectionRTU, modbusSMA::MBConnectionIP, and modbusSMA::MBConnectionIP_PI.
|
inline |
Returns the raw connection.
DO NOT close OR free it.
Definition at line 62 of file MBConnectionBase.hpp.
|
inline |
Returns whether a valid conection exists.
Definition at line 58 of file MBConnectionBase.hpp.
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
_reg | The starting register |
_num | The number of registers to read |
Definition at line 72 of file MBConnectionBase.cpp.
ErrorCode MBConnectionBase::setSlaveID | ( | int | _id | ) |
Sets the slave/uinit ID of the modbus connection.
Definition at line 100 of file MBConnectionBase.cpp.
|
pure virtual |
Returns the modbus connection type.
Implemented in modbusSMA::MBConnectionRTU, modbusSMA::MBConnectionIP, and modbusSMA::MBConnectionIP_PI.