emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add exeptions to RTU SLAVE

MarioGG7 opened this issue · comments

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();
}

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.