Not working modbus_set_response_timeout

40 views
Skip to first unread message

Дмитрий Фарафонтов

unread,
May 28, 2018, 6:57:20 AM5/28/18
to libmodbus
I'm trying to install response timeout (libmodbus 3.1.4, OS Windows 7, Visual Studio 2015):

ctx = modbus_new_rtu(connectSetting.address.c_str(), connectSetting.baud, connectSetting.parity, connectSetting.dataBit, connectSetting.stopBit);

if (ctx == nullptr) 
     LOGV << "No create ctx! error: " << modbus_strerror(errno); return false; 
}

modbus_set_response_timeout(ctx, 1, 0);

if (modbus_connect(ctx) == -1) 
{
LOGV << "No connect! error: " << modbus_strerror(errno);
return false;
}

modbus_set_slave(ctx, slaveId);

modbus_read_registers(address, cellCount, result);

And this example does not work for me.
The program waits for a response from the device endlessly and does not go out on timeout.
What am I doing wrong ?

Ole Sæther

unread,
Jun 6, 2018, 7:41:48 AM6/6/18
to libmodbus
Try setting the slave before connecting as in the example at the end of this page:
http://libmodbus.org/docs/v3.1.4/modbus_set_slave.html
Reply all
Reply to author
Forward
0 new messages