-
Notifications
You must be signed in to change notification settings - Fork 124
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
Can I write to multiple holding registers? #88
Comments
@per1234 is that something that would be a good addition to the library? If so, I can implement it with something like this: /*Take in a set of matching addresses and values those addresses to be set to */
int ModbusServer::holdingRegistersWrite(int addresses[], uint16_t values[], size_t length)
{
if(sizeof(addresses/addresses[0]) || sizeof(values/values[0]) != length)
{
return -1;
}
for(size_t element = 0; element < length; element++)
{
if (_mbMapping.start_registers > addresses[element] ||
(_mbMapping.start_registers + _mbMapping.nb_registers) < (addresses[element] + 1))
{
errno = EMBXILADD;
return 0;
}
}
for(element = 0; element < length; element++)
{
_mbMapping.tab_registers[addresses[element] - _mbMapping.start_registers] = values[element];
}
return 1;
} |
For the master/client, the write multiple registers function is supported by using
Note if memory is constrained, this can cause high memory usage due to a dynamic memory allocation to hold the register values, and large local variables in the |
In
ModbusServer.h
andModbusClient.h
I only see holdingRegisterWrite (write to a single register). Does the interface support an action for multiple writes, likewriteHoldingRegisters
? I know that the Modbus protocol does support this.The text was updated successfully, but these errors were encountered: