stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.42k stars 1.74k forks source link

set a modbus polling time #366

Closed retzbeats closed 7 years ago

retzbeats commented 7 years ago

I have tried to send an email to libmodbus@googlegroups.com but it seems the group does not exist so that's why I am asking this through this channel...

I am trying to run a Modbus client communicating with a Modbus simulator that runs on Windows, but what I am observing is that the server only receives the request (I have observed this in the simulator) but it can not answer I suppose because the client is sending to fast the requests, what I think that could help is to set a polling time but I don't know if there is a way to make this using the library functions. I suppose this because when I ran the code in the same machine using localhost address the slave (server) successfully answers the master requests (client).

I also tried to change the timeout using: modbus_set_response_timeout(ctx, 0, 5000);

but when I add that single line to the code and run it, it gaves me "Segmentation Fault".

I am using:

Ubuntu 16.04 (running the Client)

Windows 10 (running the simulator MDBUS as server)

libmodbus 3.0.6 (from the Ubuntu repository)

I am using for this random-test-client.c that comes with the library (modified to connect the ip of the computer where the simulator is running)

Regards,

Juan Guillermo Rojas A.

stephane commented 7 years ago

You must register on https://groups.google.com/forum/#!forum/libmodbus before sending an email.

By "sending too fast" you mean "it doesn't wait long enough for an answer". Responses aren't received by polling but on event.

If you use libmodbus 3.0.6, you must use this API http://libmodbus.org/docs/v3.0.6/modbus_set_response_timeout.html

libmodbus 3.1+ has a different API: http://libmodbus.org/docs/v3.1.4/modbus_set_response_timeout.html