feafea
This commit is contained in:
parent
7a4720ed02
commit
ccfc6ba7fe
9 changed files with 1805 additions and 16 deletions
|
|
@ -41,7 +41,7 @@ void Dtu::populateMicroinverters() {
|
|||
uint16_t registers[19];
|
||||
|
||||
int registerCount;
|
||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers);
|
||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers, 0);
|
||||
|
||||
if (registerCount == -1) {
|
||||
return;
|
||||
|
|
@ -64,7 +64,7 @@ void Dtu::populateMicroinverters() {
|
|||
|
||||
portStartAddress += 0x0019;
|
||||
|
||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers);
|
||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include "port.h"
|
||||
#include "sunspec.h"
|
||||
|
||||
Microinverter::Microinverter(modbus_t *modbus, int startAddress, long long serialNumber) : sunspec(40000, modbus) {
|
||||
Microinverter::Microinverter(modbus_t *modbus, int startAddress, long long serialNumber) : sunspec(0, modbus) {
|
||||
this->modbus = modbus;
|
||||
this->startAddress = startAddress;
|
||||
this->serialNumber = serialNumber;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ void Sunspec::setValues() {
|
|||
uint16_t registers[2];
|
||||
|
||||
int registerCount;
|
||||
registerCount = modbus_read_registers( this->modbus, this->sunspecAddress, 2, registers);
|
||||
registerCount = modbus_read_registers( this->modbus, this->sunspecAddress, 1, registers, 0);
|
||||
|
||||
std::vector<std::shared_ptr<SunspecParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||
while(parametersIterator != this->parameters.end()) {
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ MODBUS_API const char *modbus_strerror(int errnum);
|
|||
|
||||
MODBUS_API int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest);
|
||||
MODBUS_API int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest);
|
||||
MODBUS_API int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest);
|
||||
MODBUS_API int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest, int hoymilessunspec);
|
||||
MODBUS_API int
|
||||
modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest);
|
||||
MODBUS_API int modbus_write_bit(modbus_t *ctx, int coil_addr, int status);
|
||||
|
|
|
|||
|
|
@ -1273,11 +1273,17 @@ int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)
|
|||
}
|
||||
|
||||
/* Reads the data from a remote device and put that data into an array */
|
||||
static int read_registers(modbus_t *ctx, int function, int addr, int nb, uint16_t *dest)
|
||||
static int read_registers(modbus_t *ctx, int function, int addr, int nb, uint16_t *dest, int hoymilesSunspec)
|
||||
{
|
||||
int rc;
|
||||
int req_length;
|
||||
uint8_t req[_MIN_REQ_LENGTH];
|
||||
|
||||
int minReqLength = _MIN_REQ_LENGTH;
|
||||
if(hoymilesSunspec != 0) {
|
||||
minReqLength++;
|
||||
}
|
||||
|
||||
uint8_t req[minReqLength];
|
||||
uint8_t rsp[MAX_MESSAGE_LENGTH];
|
||||
|
||||
if (nb > MODBUS_MAX_READ_REGISTERS) {
|
||||
|
|
@ -1293,6 +1299,15 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, uint16_
|
|||
|
||||
req_length = ctx->backend->build_request_basis(ctx, function, addr, nb, req);
|
||||
|
||||
if(hoymilesSunspec != 0) {
|
||||
req_length++;
|
||||
for(int i = req_length - 1; i>1; i--) {
|
||||
req[i] = req[i-1];
|
||||
}
|
||||
// req[0] = 0;
|
||||
req[1] = 7;
|
||||
}
|
||||
|
||||
|
||||
rc = send_msg(ctx, req, req_length);
|
||||
if (rc > 0) {
|
||||
|
|
@ -1300,6 +1315,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, uint16_
|
|||
int i;
|
||||
|
||||
rc = _modbus_receive_msg(ctx, rsp, MSG_CONFIRMATION);
|
||||
|
||||
if (rc == -1)
|
||||
return -1;
|
||||
|
||||
|
|
@ -1320,7 +1336,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, uint16_
|
|||
|
||||
/* Reads the holding registers of remote device and put the data into an
|
||||
array */
|
||||
int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
|
||||
int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest, int hoymilesSunspec)
|
||||
{
|
||||
int status;
|
||||
|
||||
|
|
@ -1340,7 +1356,7 @@ int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
|
|||
return -1;
|
||||
}
|
||||
|
||||
status = read_registers(ctx, MODBUS_FC_READ_HOLDING_REGISTERS, addr, nb, dest);
|
||||
status = read_registers(ctx, MODBUS_FC_READ_HOLDING_REGISTERS, addr, nb, dest, hoymilesSunspec);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
@ -1363,7 +1379,7 @@ int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
|
|||
return -1;
|
||||
}
|
||||
|
||||
status = read_registers(ctx, MODBUS_FC_READ_INPUT_REGISTERS, addr, nb, dest);
|
||||
status = read_registers(ctx, MODBUS_FC_READ_INPUT_REGISTERS, addr, nb, dest, 0);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue