Starting to move thte library
This commit is contained in:
parent
f6b42b2460
commit
381dcbdc57
14 changed files with 750 additions and 21 deletions
|
|
@ -9,13 +9,14 @@
|
|||
|
||||
#include "portParameters.h"
|
||||
|
||||
struct _modbus;
|
||||
typedef _modbus modbus_t;
|
||||
// struct _modbus;
|
||||
// typedef _modbus modbus_t;
|
||||
|
||||
Dtu::Dtu(const char *ip_address, int port) {
|
||||
this->modbus_context = std::make_shared<modbus_t*>(modbus_new_tcp(ip_address, port));
|
||||
class modbus modbus{ip_address, (uint16_t) port};
|
||||
this->modbus = std::make_shared<class modbus>(modbus);
|
||||
|
||||
if (modbus_connect(*this->modbus_context.get()) == -1) {
|
||||
if (!this->modbus.get()->modbus_connect()) {
|
||||
std::cerr << "conn_error";
|
||||
this->connected = false;
|
||||
}
|
||||
|
|
@ -33,8 +34,7 @@ bool Dtu::isConnected() {
|
|||
}
|
||||
|
||||
Dtu::~Dtu() {
|
||||
modbus_close(*this->modbus_context.get());
|
||||
modbus_free(*this->modbus_context.get());
|
||||
this->modbus.get()->modbus_close();
|
||||
}
|
||||
|
||||
void Dtu::populateMicroinverters() {
|
||||
|
|
@ -42,12 +42,12 @@ void Dtu::populateMicroinverters() {
|
|||
uint16_t readArray[1];
|
||||
|
||||
int registerCount;
|
||||
registerCount = modbus_read_registers(*this->modbus_context.get(), portStartAddress + 0x0021, 1, readArray);
|
||||
registerCount = this->modbus.get()->modbus_read_holding_registers(portStartAddress + 0x0021, 1, readArray);
|
||||
while(registerCount != -1 && readArray[0] == 0x700) {
|
||||
Port port{ this->modbus_context, portStartAddress };
|
||||
Port port{ this->modbus, portStartAddress };
|
||||
|
||||
PortParameterMicroinverterSerialNumber portParameterMicroinverterSerialNumber{};
|
||||
portParameterMicroinverterSerialNumber.updateValue(this->modbus_context, portStartAddress);
|
||||
portParameterMicroinverterSerialNumber.updateValue(this->modbus, portStartAddress);
|
||||
long serialNumber = portParameterMicroinverterSerialNumber.getValue().first.i;
|
||||
|
||||
std::pair<bool, Microinverter*> getMicroinverterBySerialNumber = this->getMicroinverterBySerialNumber(serialNumber);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue