Commit 8f597f8e authored by Locatelli's avatar Locatelli

Prepare installation of new libmodbus version

parent 0bc3d15c
......@@ -93,10 +93,13 @@ void ModBusRTU::openModBus(int32 address) throw (OpenError) {
modbus_set_debug(m_Ctx, false);
modbus_set_error_recovery(m_Ctx, (modbus_error_recovery_mode) (MODBUS_ERROR_RECOVERY_LINK | MODBUS_ERROR_RECOVERY_PROTOCOL));
modbus_set_slave(m_Ctx, address);
#if (LIBMODBUS_VERSION_CHECK(3,1,4))
modbus_set_response_timeout(m_Ctx, 2, 0);
#else
struct timeval response_timeout;
response_timeout.tv_sec = 2;
response_timeout.tv_usec = 0;
modbus_set_response_timeout(m_Ctx, &response_timeout);
#endif
if (modbus_connect(m_Ctx) == -1) {
cerr << "Connection failed : " << modbus_strerror(errno) << endl;
modbus_free(m_Ctx);
......
......@@ -59,11 +59,14 @@ void ModBusTCP::openModBus(int32 channel) throw (OpenError) {
modbus_set_debug(m_Ctx, false);
modbus_set_error_recovery(m_Ctx, (modbus_error_recovery_mode) (MODBUS_ERROR_RECOVERY_LINK | MODBUS_ERROR_RECOVERY_NONE));
modbus_set_slave(m_Ctx, channel);
#if (LIBMODBUS_VERSION_CHECK(3,1,4))
modbus_set_response_timeout(m_Ctx, 2, 0);
#else
struct timeval response_timeout;
response_timeout.tv_sec = 2;
response_timeout.tv_usec = 0;
modbus_set_response_timeout(m_Ctx, &response_timeout);
if (modbus_connect(m_Ctx) == -1) {
#endif
if (modbus_connect(m_Ctx) == -1) {
cerr << "Connection failed on " << ipAddress() << " (" << channel << ") : " << modbus_strerror(errno) << endl;
modbus_free(m_Ctx);
m_Ctx = NULL;
......
......@@ -16,9 +16,9 @@
* limitations under the Licence.
*/
#ifndef MODBUS_H
#ifndef MODBUSLEGACY_H
#define MODBUS_H
#define MODBUSLEGACY_H
#include <stdio.h>
#include <stdlib.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment