Am 01.05.2014 11:12, schrieb sepei:
> But I dont get it whats wrong with my source.
> I'm getting the error: "test1: modbus-rtu.c:119:
> _modbus_rtu_build_request_basis: Assertion `ctx->slave != -1' failed."
[...]
> I was debugging the programm and till "rc = modbus_read_registers(ctx,
> 14, 2, tab_reg);" it works fine but there I just get the above error.
I think you have to call modbus_set_slave() before any read or write
function.
An assertion failure is not a good error handling in this case. IMHO
assertions should only be used for programming errors in internal to the
library not for errors caused by the calling program. A better reaction
would be to return an error code (rc < 0) from modbus_read_registers()
and set errno to specify the details.
Bodo