modbus_set_response_timeout cause segmentation fault

451 views
Skip to first unread message

Antoine Croteau

unread,
Jan 8, 2016, 1:32:11 PM1/8/16
to libmodbus

Hello people,

 

 

 

I'm currently coding a C++ program running on a stripped down Linux. I'm using Buildroot to compile the libraries.

 

 

 

I am using Libmodbus version 3.1.2. To get that version working, I had to modify Buildroot's Libmodbus package with  "LIBMODBUS_VERSION = 3.1.2", "LIBMODBUS_LIBTOOL_PATCH= NO" and remake.

 

 

 

I can Read/Write in TCP/UDP, everything works fine, except when I try to do a "modbus_set_response_timeout".

 

When I call it, I get a segmentation fault. I have no idea what can cause this. Even the "modbus_get_response_timeout" works. I just tried modbus_set_byte_timeout and it cause a seg fault too...

 

 

 

Sorry I don't have much more information, but it's pretty straightforward.

 

 

 

Anyone have any idea? Maybe I should just go back to 3.0.6.

 

 

 

Thanks a lot, Antoine

Stéphane Raimbault

unread,
Jan 8, 2016, 4:02:01 PM1/8/16
to libm...@googlegroups.com
Could you paste the code you use to set the timeout?

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "libmodbus".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Antoine Croteau

unread,
Jan 13, 2016, 2:36:36 PM1/13/16
to libmodbus
mModbusContext = modbus_new_tcp_pi(mIPAddr.c_str(), mIPPort.c_str());

if (mModbusContext == nullptr)
{
   mError = errno;
   return false;
}
else
{
    modbus_set_response_timeout(mModbusContext, 0, 200000);
}

if (modbus_connect(mModbusContext) == -1)
{
   mError = errno;
   modbus_free(mModbusContext);
   mModbusContext = nullptr;
   return false;
}

return true;


Thank you for your time and the fast answer.
Message has been deleted

Antoine Croteau

unread,
Jan 13, 2016, 3:20:51 PM1/13/16
to libmodbus

When I run my program with Valgrind, I get the following on the modbus_set_response_timeout call :

==1430== Invalid read of size 4
==1430==    at 0x4C234E8: modbus_set_response_timeout (in /usr/lib/libmodbus.so.5.0.4)
==1430==  Address 0x0 is not stack'd, malloc'd or (recently) free'd



Valgrind doesnt seem very explicit. I don't know if this will help.

Stéphane Raimbault

unread,
Jan 15, 2016, 6:02:38 PM1/15/16
to libm...@googlegroups.com
I think you don't use the right version of the library.
/usr/lib/libmodbus.so.5.0.4 must be v3.0.X where as the API you use is for v3.1.X and above.

--

Antoine Croteau

unread,
Jan 18, 2016, 1:04:37 PM1/18/16
to libmodbus
Ooohh, that's it. I forgot to copy the .so compiled with Buildroot in my program's lib folder..

It works great now. Thanks a lot for the library and answering my question.

Have a good day,
Antoine

Muhammad U. Anwar

unread,
Apr 3, 2018, 9:01:56 AM4/3/18
to libmodbus
Hi,

I am having the same problem as @Antoine Croteau. Can anyone please help me what is the described solution in little bit more detail. 

Thanks, 

zouro...@gmail.com

unread,
Jul 3, 2018, 10:28:53 AM7/3/18
to libmodbus
Hi Stephane,

The library is really great! I just have a problem with the set_response_timeout function where it causes a segmentation fault. Would you please advise me on this?

Thanks.
Reply all
Reply to author
Forward
0 new messages