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

How to add exeptions to RTU SLAVE #354

Closed
MarioGG7 opened this issue Jun 5, 2024 · 1 comment
Closed

How to add exeptions to RTU SLAVE #354

MarioGG7 opened this issue Jun 5, 2024 · 1 comment

Comments

@MarioGG7
Copy link

MarioGG7 commented Jun 5, 2024

mb.slave(SLAVE_ID);
mb.addHreg(REGN);
mb.Hreg(REGN, 100);
....................... if(REGN > 150){"send exeption -3 illegal value"}; // how to do this? ..............
}

void loop() {
mb.task();
yield();
}

@emelianov
Copy link
Owner

Is not exactly clear at which point you want to get exception.
As of Modbus specification EX_ILLEGAL_ADDRESS is returned to master on non-existent address. If you want to override this behaviour you can use onRaw() callback but much easier is to modify the library code for this specific case.
If you want to block addReg() from adding registers on some condition you have to inherit own class from ModbusRTU and override addReg() implementation.

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

No branches or pull requests

2 participants