aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-03-13 01:58:25 +0000
committerJonathan McCrohan <jmccrohan@gmail.com>2012-03-13 02:03:20 +0000
commit1cac28534c332d771bfd7a1a216bdaacbfe27fd1 (patch)
treef70e3a861b4edda8a730c5edc02ec06df61181c2
parenta8e3c622928d4af3eee81729656f05717d6dd233 (diff)
downloadverteco-1cac28534c332d771bfd7a1a216bdaacbfe27fd1.tar.gz
modbuslog: improve error handling
-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;