From: Ruben Kerkhof Date: Fri, 26 Feb 2016 21:53:19 +0000 (+0100) Subject: Merge branch 'collectd-5.4' into collectd-5.5 X-Git-Tag: collectd-5.5.2~62 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=3307054b6ab46b51fdda4f528e72d119e9de3071;p=collectd.git Merge branch 'collectd-5.4' into collectd-5.5 --- 3307054b6ab46b51fdda4f528e72d119e9de3071 diff --cc src/modbus.c index 97b98b7c,7349dc56..c04b308d --- a/src/modbus.c +++ b/src/modbus.c @@@ -362,35 -330,22 +364,37 @@@ static int mb_init_connection (mb_host_ if (host->connection != NULL) return (0); - if ((host->port < 1) || (host->port > 65535)) - host->port = MODBUS_TCP_DEFAULT_PORT; + if (host->conntype == MBCONN_TCP) + { + if ((host->port < 1) || (host->port > 65535)) + host->port = MODBUS_TCP_DEFAULT_PORT; - DEBUG ("Modbus plugin: Trying to connect to \"%s\", port %i.", - host->node, host->port); + DEBUG ("Modbus plugin: Trying to connect to \"%s\", port %i.", + host->node, host->port); - host->connection = modbus_new_tcp (host->node, host->port); - if (host->connection == NULL) + host->connection = modbus_new_tcp (host->node, host->port); + if (host->connection == NULL) + { + ERROR ("Modbus plugin: Creating new Modbus/TCP object failed."); + return (-1); + } + } + else { - ERROR ("Modbus plugin: Creating new Modbus/TCP object failed."); - return (-1); + DEBUG ("Modbus plugin: Trying to connect to \"%s\", baudrate %i.", + host->node, host->baudrate); + + host->connection = modbus_new_rtu (host->node, host->baudrate, 'N', 8, 1); + if (host->connection == NULL) + { + ERROR ("Modbus plugin: Creating new Modbus/RTU object failed."); + return (-1); + } } + #if COLLECT_DEBUG modbus_set_debug (host->connection, 1); + #endif /* We'll do the error handling ourselves. */ modbus_set_error_recovery (host->connection, 0);