diff --git a/src/modbus-rtu.c b/src/modbus-rtu.c index 0d750b3..bae99b2 100644 --- a/src/modbus-rtu.c +++ b/src/modbus-rtu.c @@ -351,7 +351,7 @@ static int _modbus_rtu_pre_check_confirmation(modbus_t *ctx, const uint8_t *req, if (req[0] != rsp[0] && req[0] != MODBUS_BROADCAST_ADDRESS) { if (ctx->debug) { fprintf(stderr, - "The responding slave %d isn't the requested slave %d", + "The responding slave %d isn't the requested slave %d\n", rsp[0], req[0]); } errno = EMBBADSLAVE; @@ -371,13 +371,13 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, uint16_t crc_received; int slave = msg[0]; - /* Filter on the Modbus unit identifier (slave) in RTU mode */ + /* Filter on the Modbus unit identifier (slave) in RTU mode to avoid useless + * CRC computing. */ if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS) { - /* Ignores the request (not for me) */ if (ctx->debug) { printf("Request for slave %d ignored (not %d)\n", slave, ctx->slave); } - + /* Following call to check_confirmation handles this error */ return 0; } diff --git a/src/modbus.c b/src/modbus.c index 30b6d3f..59803b1 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -1468,8 +1468,6 @@ int modbus_write_and_read_registers(modbus_t *ctx, return -1; offset = ctx->backend->header_length; - - /* If rc is negative, the loop is jumped ! */ for (i = 0; i < rc; i++) { /* shift reg hi_byte to temp OR with lo_byte */ dest[i] = (rsp[offset + 2 + (i << 1)] << 8) |