ModbusSMA  v1.0.0
modbusSMA::ModbusAPI Class Reference

Main ModbusSMA class. More...

#include <ModbusAPI.hpp>

Public Member Functions

 ModbusAPI (std::string _ip, uint32_t _port, std::shared_ptr< DataBase > _db=nullptr)
 Initializes the ModbusAPI with a custom TCP IP and port. More...
 
 ModbusAPI (std::string _node, std::string _service, std::shared_ptr< DataBase > _db=nullptr)
 Initializes the ModbusAPI with a custom IP and port. More...
 
 ModbusAPI (std::string _device, uint32_t _baud, char _parity, int _dataBit, int _stopBit, std::shared_ptr< DataBase > _db=nullptr)
 Initializes the ModbusAPI with a RTU connectopm. More...
 
 ModbusAPI (std::string _ip, uint32_t _port, std::string _dbPath)
 Wrapper for the other constructor.
 
 ModbusAPI (std::string _node, std::string _service, std::string _dbPath)
 Wrapper for the other constructor.
 
 ModbusAPI (std::string _device, uint32_t _baud, char _parity, int _dataBit, int _stopBit, std::string _dbPath)
 Wrapper for the other constructor.
 
 ModbusAPI (ModbusAPI const &)=delete
 
void operator= (ModbusAPI const &)=delete
 
ErrorCode connect ()
 Establishes the modbus connection based on the current configuration. More...
 
ErrorCode initialize ()
 Initializes the API. More...
 
ErrorCode setup ()
 Wrapper for connect() and initialize() More...
 
void reset ()
 Resets the state of the object (modbus connection, inverter type, etc.) to CONFIGURE. More...
 
ErrorCode updateRegisters (std::vector< uint16_t > _regList, size_t *_numUpdated=nullptr)
 Convinience wrapper for the other version of this function.
 
ErrorCode updateRegisters (std::vector< Register > _regList, size_t *_numUpdated=nullptr)
 Updates all registers stored in _regList. More...
 
ErrorCode setDataBase (std::shared_ptr< DataBase > _db)
 Sets the modbus register database to use. More...
 
ErrorCode setDataBase (std::string _dbPath)
 Sets the modbus register database to use. More...
 
ErrorCode setConnectionTCP_IP (std::string _ip, uint32_t _port)
 Sets the TCP server connection details. More...
 
ErrorCode setConnectionTCP_IP_PI (std::string _node, std::string _service)
 Sets the TCP IP protocol indemendant server connection details. More...
 
ErrorCode setConnectionRTU (std::string _device, uint32_t _baud, char _parity, int _dataBit, int _stopBit)
 Sets the TCP server connection details. More...
 
State getState () const
 Returns the current state. More...
 
std::shared_ptr< DataBasegetDataBase ()
 Returns the used DataBase. More...
 
std::shared_ptr< RegisterContainergetRegisters () const
 Returns the registers. More...
 
std::string inverterType () const
 Returns the inverter type. More...
 
uint32_t inverterTypeID () const
 Returns the inverter type (ID). More...
 

Detailed Description

Main ModbusSMA class.

This class is the main ModbusSMA interface. The connection to the modbus interface is handled here.

The following state machine illustrates the state changes of this class:

Definition at line 100 of file ModbusAPI.hpp.

Constructor & Destructor Documentation

◆ ModbusAPI() [1/3]

ModbusAPI::ModbusAPI ( std::string  _ip,
uint32_t  _port,
std::shared_ptr< DataBase _db = nullptr 
)

Initializes the ModbusAPI with a custom TCP IP and port.

See also
setConnectionTCP_IP
Parameters
_ipThe IP address of the inverter.
_portThe modbus TCP port.
_dbDatabase describing the modbus registers.

Definition at line 35 of file ModbusAPI.cpp.

◆ ModbusAPI() [2/3]

ModbusAPI::ModbusAPI ( std::string  _node,
std::string  _service,
std::shared_ptr< DataBase _db = nullptr 
)

Initializes the ModbusAPI with a custom IP and port.

See also
setConnectionTCP_IP
Parameters
_nodeThe Modbus node (IP address, DNS name, etc.) of the inverter.
_serviceThe service to connect to.
_dbDatabase describing the modbus registers.

Definition at line 47 of file ModbusAPI.cpp.

◆ ModbusAPI() [3/3]

ModbusAPI::ModbusAPI ( std::string  _device,
uint32_t  _baud,
char  _parity,
int  _dataBit,
int  _stopBit,
std::shared_ptr< DataBase _db = nullptr 
)

Initializes the ModbusAPI with a RTU connectopm.

See also
setConnectionRTU
Parameters
_deviceThe name / path of the serial port.
_baudRTU connection baud rate.
_parityPartity type: N = None; E = Even; O = Odd.
_dataBitThe number of bits of data, the allowed values are 5, 6, 7 and 8
_stopBitThe bits of stop, the allowed values are 1 and 2.
_dbDatabase describing the modbus registers.

Definition at line 60 of file ModbusAPI.cpp.

Member Function Documentation

◆ connect()

ErrorCode ModbusAPI::connect ( )

Establishes the modbus connection based on the current configuration.

State change: CONFIGURE –> CONNECTED | ERROR

Definition at line 109 of file ModbusAPI.cpp.

◆ getDataBase()

std::shared_ptr<DataBase> modbusSMA::ModbusAPI::getDataBase ( )
inline

Returns the used DataBase.

Definition at line 146 of file ModbusAPI.hpp.

◆ getRegisters()

std::shared_ptr<RegisterContainer> modbusSMA::ModbusAPI::getRegisters ( ) const
inline

Returns the registers.

Definition at line 147 of file ModbusAPI.hpp.

◆ getState()

State modbusSMA::ModbusAPI::getState ( ) const
inline

Returns the current state.

Definition at line 145 of file ModbusAPI.hpp.

◆ initialize()

ErrorCode ModbusAPI::initialize ( )

Initializes the API.

This function connects to the DataBase (if not already done) and initializes the API by querying basic information (uinit id, inverter type) from the modbus interface

State change: CONNECTED –> INITIALIZED | ERROR

Definition at line 137 of file ModbusAPI.cpp.

◆ inverterType()

std::string modbusSMA::ModbusAPI::inverterType ( ) const
inline

Returns the inverter type.

Definition at line 149 of file ModbusAPI.hpp.

◆ inverterTypeID()

uint32_t modbusSMA::ModbusAPI::inverterTypeID ( ) const
inline

Returns the inverter type (ID).

Definition at line 150 of file ModbusAPI.hpp.

◆ reset()

void ModbusAPI::reset ( )

Resets the state of the object (modbus connection, inverter type, etc.) to CONFIGURE.

The configuration (IP, port) is NOT reset.

State change: * –> CONFIGURE

Definition at line 94 of file ModbusAPI.cpp.

◆ setConnectionRTU()

ErrorCode ModbusAPI::setConnectionRTU ( std::string  _device,
uint32_t  _baud,
char  _parity,
int  _dataBit,
int  _stopBit 
)

Sets the TCP server connection details.

Note
This function can only be called in the CONFIGURE state

State change: NONE

Parameters
_deviceThe name of the serial port
_baudThe baud rate of the communication
_parityPartity type: N = None; E = Even; O = Odd
_dataBitThe number of bits of data, the allowed values are 5, 6, 7 and 8
_stopBitThe bits of stop, the allowed values are 1 and 2
Returns
OK or INVALID_STATE

Definition at line 450 of file ModbusAPI.cpp.

◆ setConnectionTCP_IP()

ErrorCode ModbusAPI::setConnectionTCP_IP ( std::string  _ip,
uint32_t  _port 
)

Sets the TCP server connection details.

Note
This function can only be called in the CONFIGURE state

State change: NONE

Parameters
_ipThe IP address to use
_portThe port to use
Returns
OK or INVALID_STATE

Definition at line 403 of file ModbusAPI.cpp.

◆ setConnectionTCP_IP_PI()

ErrorCode ModbusAPI::setConnectionTCP_IP_PI ( std::string  _node,
std::string  _service 
)

Sets the TCP IP protocol indemendant server connection details.

Note
This function can only be called in the CONFIGURE state

State change: NONE

Parameters
_nodeThe server node
_serviceThe service
Returns
OK or INVALID_STATE

Definition at line 425 of file ModbusAPI.cpp.

◆ setDataBase() [1/2]

ErrorCode ModbusAPI::setDataBase ( std::shared_ptr< DataBase _db)

Sets the modbus register database to use.

Note
This function can only be called in the CONFIGURE state

State change: NONE

Parameters
_dbshared pointer to the DataBase object
Returns
OK or INVALID_STATE

Definition at line 356 of file ModbusAPI.cpp.

◆ setDataBase() [2/2]

ErrorCode ModbusAPI::setDataBase ( std::string  _dbPath)

Sets the modbus register database to use.

Note
This function can only be called in the CONFIGURE state

State change: NONE

Parameters
_dbPathPath to the database file
Returns
OK or INVALID_STATE

Definition at line 378 of file ModbusAPI.cpp.

◆ setup()

ErrorCode ModbusAPI::setup ( )

Wrapper for connect() and initialize()

State change: CONFIGURE –> INITIALIZED | ERROR

Definition at line 236 of file ModbusAPI.cpp.

◆ updateRegisters()

ErrorCode ModbusAPI::updateRegisters ( std::vector< Register _regList,
size_t *  _numUpdated = nullptr 
)

Updates all registers stored in _regList.

Fethes the register values from the inverter and stores the values in the shared RegisterContainer. The updated register values can then examined by requesting the registers from the RegisterContainer.

Unsupported registers (by the inverter) in _regList are ignored.

Note
This function can only be called in the INITIALIZED state

State change: NONE

Parameters
[in]_regListList of registers to update
[out]_numUpdatedNumber of updated registers

Definition at line 276 of file ModbusAPI.cpp.


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