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

ModbusClient.requestFrom() crashes Finder Opta if id > 247 #151

Open
gareddustephane opened this issue May 14, 2024 · 0 comments
Open

ModbusClient.requestFrom() crashes Finder Opta if id > 247 #151

gareddustephane opened this issue May 14, 2024 · 0 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@gareddustephane
Copy link

gareddustephane commented May 14, 2024

When implementing Modbus RTU on an Opta Finder, with the classical Arduino IDE, in order to read coils on a remote slave (server), we must use the following method :

int requestFrom(int id, int type, int address,int nb);

However, the device crashes if the id is greater than 247 as in the following piece of code :

ModbusRTUClient.requestFrom(248, COILS, 0x00, 10)

the RESET LED blinks red and no code is executed. Moreover, we can't upload a sketch anymore onto the device. The RESET button has to be pressed twice in order to make the Opta Finder be recognized again.

The only place in the requestFrom() method where the id is used here :

modbus_set_slave(_mb, id);

Calling this function:

/* Define the slave ID of the remote device to talk in master mode or set the
* internal slave ID in slave mode */
static int _modbus_set_slave(modbus_t *ctx, int slave)
{
/* Broadcast address is 0 (MODBUS_BROADCAST_ADDRESS) */
if (slave >= 0 && slave <= 247) {
ctx->slave = slave;
} else {
errno = EINVAL;
return -1;
}
return 0;
}

Hence, here, a test is performed in order to verify the id of the targeted slave. But as the line modbus_set_slave(_mb, id); in the requestFrom() method doesn't, this leads to a crash. In other words, the error raised by modbus-rtu.cpp is not propagated to the requestFrom() method.

This could be easily fixed by making a simple check.

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants