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

Ignore Callbacks when Register is Updated by Self

seikosantana opened this issue · comments

Hi, is there a way to update register value without triggering the onSetCoil / onSetHreg?
I am trying to integrate modbus into existing working program so that it can interface with modbus, but the problem is when I use onSetCoil/onSetHreg to handle incoming requests, and have my program to update the registers to represent the current state, it fires the callbacks too, causing recursive calls or long loops.

Do you have any tips or workarounds for this kind of situation? Thanks in advance

mb.cbDisable();
mb.Hreg(REV, VALUE);
mb.cbEnable();

Or safer variant

bool saved_state = mb.cbEnable(false);
mb.Hreg(REV, VALUE);
mb.cbEnable(saved_state);

Is it safe to call those in a callback itself (inside an onSet)?

Thanks a lot for your response and effort on the library 😀