Skip to content

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

Open
@gareddustephane

Description

@gareddustephane

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions