ModbusSMA
v1.0.0
|
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< DataBase > | getDataBase () |
Returns the used DataBase. More... | |
std::shared_ptr< RegisterContainer > | getRegisters () const |
Returns the registers. More... | |
std::string | inverterType () const |
Returns the inverter type. More... | |
uint32_t | inverterTypeID () const |
Returns the inverter type (ID). More... | |
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.
ModbusAPI::ModbusAPI | ( | std::string | _ip, |
uint32_t | _port, | ||
std::shared_ptr< DataBase > | _db = nullptr |
||
) |
Initializes the ModbusAPI with a custom TCP IP and port.
_ip | The IP address of the inverter. |
_port | The modbus TCP port. |
_db | Database describing the modbus registers. |
Definition at line 35 of file ModbusAPI.cpp.
ModbusAPI::ModbusAPI | ( | std::string | _node, |
std::string | _service, | ||
std::shared_ptr< DataBase > | _db = nullptr |
||
) |
Initializes the ModbusAPI with a custom IP and port.
_node | The Modbus node (IP address, DNS name, etc.) of the inverter. |
_service | The service to connect to. |
_db | Database describing the modbus registers. |
Definition at line 47 of file ModbusAPI.cpp.
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.
_device | The name / path of the serial port. |
_baud | RTU connection baud rate. |
_parity | Partity type: N = None; E = Even; O = Odd. |
_dataBit | The number of bits of data, the allowed values are 5, 6, 7 and 8 |
_stopBit | The bits of stop, the allowed values are 1 and 2. |
_db | Database describing the modbus registers. |
Definition at line 60 of file ModbusAPI.cpp.
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.
|
inline |
Returns the used DataBase.
Definition at line 146 of file ModbusAPI.hpp.
|
inline |
Returns the registers.
Definition at line 147 of file ModbusAPI.hpp.
|
inline |
Returns the current state.
Definition at line 145 of file ModbusAPI.hpp.
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.
|
inline |
Returns the inverter type.
Definition at line 149 of file ModbusAPI.hpp.
|
inline |
Returns the inverter type (ID).
Definition at line 150 of file ModbusAPI.hpp.
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.
ErrorCode ModbusAPI::setConnectionRTU | ( | std::string | _device, |
uint32_t | _baud, | ||
char | _parity, | ||
int | _dataBit, | ||
int | _stopBit | ||
) |
Sets the TCP server connection details.
State change: NONE
_device | The name of the serial port |
_baud | The baud rate of the communication |
_parity | Partity type: N = None; E = Even; O = Odd |
_dataBit | The number of bits of data, the allowed values are 5, 6, 7 and 8 |
_stopBit | The bits of stop, the allowed values are 1 and 2 |
Definition at line 450 of file ModbusAPI.cpp.
ErrorCode ModbusAPI::setConnectionTCP_IP | ( | std::string | _ip, |
uint32_t | _port | ||
) |
Sets the TCP server connection details.
State change: NONE
_ip | The IP address to use |
_port | The port to use |
Definition at line 403 of file ModbusAPI.cpp.
ErrorCode ModbusAPI::setConnectionTCP_IP_PI | ( | std::string | _node, |
std::string | _service | ||
) |
Sets the TCP IP protocol indemendant server connection details.
State change: NONE
_node | The server node |
_service | The service |
Definition at line 425 of file ModbusAPI.cpp.
Sets the modbus register database to use.
State change: NONE
_db | shared pointer to the DataBase object |
Definition at line 356 of file ModbusAPI.cpp.
ErrorCode ModbusAPI::setDataBase | ( | std::string | _dbPath | ) |
Sets the modbus register database to use.
State change: NONE
_dbPath | Path to the database file |
Definition at line 378 of file ModbusAPI.cpp.
ErrorCode ModbusAPI::setup | ( | ) |
Wrapper for connect() and initialize()
State change: CONFIGURE –> INITIALIZED | ERROR
Definition at line 236 of file ModbusAPI.cpp.
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.
State change: NONE
[in] | _regList | List of registers to update |
[out] | _numUpdated | Number of updated registers |
Definition at line 276 of file ModbusAPI.cpp.