Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Inverter parameters / function code 0x04 #85

Open
git-greatguy opened this issue Oct 5, 2024 · 0 comments
Open

Read Inverter parameters / function code 0x04 #85

git-greatguy opened this issue Oct 5, 2024 · 0 comments

Comments

@git-greatguy
Copy link

Hi,

I want to read resgisters from command 0x04.
Tried to modify existing code to fit my need but no luck at the moment.

I'm not a modbus specialist and i think commands i send to inverter is wrong. (calculated crc error ?).

Here is what i did so far.

added a new function code 0x04

#define MODBUS_FN_READSINGLEREG 0x03
#define MODBUS_FN_READSINGLEREG2 0x04 

added a new variable "regval" for this function code to store along with register which we want to read.
struct mqtt_status_register

{
	uint16_t regnum;
	String    mqtt_name;
        uint16_t regval;
};

#define SOFAR_REG_BMCV 0x10B3

Declaration of one register we want to read on this new function code
static struct mqtt_status_register mqtt_status_reads[] =

{
[...]
{ SOFAR_REG_BMCV, "max_charge_voltage", MODBUS_FN_READSINGLEREG2 },
}

modified function addstateinfo

int addStateInfo(String &state, uint16_t reg, String human, uint16_t regval)
{
	unsigned int	val;
	modbusResponse	rs;

	if(readSingleReg(SOFAR_SLAVE_ID, reg, &rs, regval))
		return -1;

	val = ((rs.data[0] << 8) | rs.data[1]);

	if (!( state == "{"))
		state += ",";

	state += "\"" + human + "\":" + String(val);
	return 0;
}

modified readSingleReg function ( i think this is here i missed something with crc)

int readSingleReg(uint8_t id, uint16_t reg, modbusResponse *rs, uint16_t regval)
{
	uint8_t	frame[] = { id, regval, reg >> 8, reg & 0xff, 0, 0x01, 0, 0 };

	return sendModbus(frame, sizeof(frame), rs);
}

Any help to get this working ? Ask me if you want more informations !

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant