-
Notifications
You must be signed in to change notification settings - Fork 190
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
Trying to increment a Holding Register every time what the Master reads an expecific Holding Register... #276
Comments
I'm afraid the goal is not clear for me. |
Hello @emelianov, I create a Holding register or Input Register,like 5 or 10 with a initial number, I like to check every time this register is read, it will be incremented or decremented with each reading. Like
What the function |
You have to do it like this:
|
This solution is AMAZING! I Will test soon! Thank you!
Em sáb., 9 de dez. de 2023 às 06:31, fredlcore ***@***.***>
escreveu:
… You have to do it like this:
Set up a callback function to be called every time a holding register is
queried. In this function you change the register as you please:
uint16_t cb(TRegister* reg, uint16_t val) {
x++;
mb.Hreg(101, x);
return val;
}
x must be a global variable, otherwise it will be out of scope.
In setup, you have to define the callback function (assuming that mb is
your Modbus object):
mb.onGetHreg((101, cb);
—
Reply to this email directly, view it on GitHub
<#276 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB4XIPOK5KE4R2XCXJQAREDYIQVXPAVCNFSM6AAAAAAWC6JGPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBYGM2DKMBRG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Wagner de Queiroz
Be free with Linux
|
I just realized that it might have to be |
Also, if you want to perform different actions based on the holding register address, you can do something like |
I need understand how to work the modbus.OnGetHreg(register)...
What I need. Each timer whats the master try read an expecific Holding Register, I need increment or Decrement the reading, but I put this loop and I get random values.... I think this is increment x every time what loop runs...
Any hint about how I can get my objective?
The text was updated successfully, but these errors were encountered: