aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/modbuslog.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/modbuslog.c b/src/modbuslog.c
index 8a9da3a..51895ac 100644
--- a/src/modbuslog.c
+++ b/src/modbuslog.c
@@ -214,17 +214,20 @@ int main(int argc, char *argv[]) {
ctx = modbus_new_rtu(modbus_device_address, modbus_baud_rate,
modbus_parity[0], modbus_data_bits, modbus_stop_bits);
- modbus_set_slave(ctx, slaveid);
- modbus_set_debug(ctx, DEBUG);
-
if (ctx == NULL) {
syslog(LOG_ERR, "Unable to create libmodbus object");
}
+ modbus_set_slave(ctx, slaveid);
+ modbus_set_debug(ctx, DEBUG);
+
if (modbus_connect(ctx) == -1) {
syslog(LOG_ERR, "libmodbus: Connection failed: [%s]",
modbus_strerror(errno));
modbus_free(ctx);
+ // if connection fails, skip rest of loop
+ syslog(LOG_ERR, "Skipping read from [%i,%i]", slaveid, startaddress);
+ break;
}
int retry = 0;