test TCP modbus connection

Asked by Alexander Yang

Hi,

in my application is libmodbus used for communication per TCP.

the issue is, if libmodbus provides a possibility to test current tcp connection,
i want to check the tcp connection in my program before continuing communication with other modbus device.
if the connection is broken(e.g. machine is down, cable is broken, etc), something will be done for processing this.

the most solutions in Internet is using TCP keepalive mechanism, but it is difficult to integrate it into libmodbus,
i feel, it is fine if libmodbus provides a corresponding function to do that check.

thanks

Alex

Question information

Language:
English Edit question
Status:
Solved
For:
libmodbus Edit question
Assignee:
No assignee Edit question
Solved by:
Stéphane Raimbault
Solved:
Last query:
Last reply:
Revision history for this message
Best Stéphane Raimbault (sra) said :
#1

libmodbus provides a function to recover on errors (see http://libmodbus.org/site_media/html/modbus_set_error_recovery.html) and you can use the error codes of each libmodbus functions to know how the communication has failed (modbus, wire, etc).

Revision history for this message
Alexander Yang (dianqiang) said :
#2

Thanks Stéphane Raimbault, that solved my question.