aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-04-04 00:11:39 +0100
committerJonathan McCrohan <jmccrohan@gmail.com>2012-04-04 00:11:39 +0100
commit41c3d98e8951107970a35f6104e1cbf15cd87ada (patch)
tree4753be121345540effa3c26cdce5a7f7f8796e2e
parent39c058cb9a21d8c093fb14a4f4a013195a0eaf88 (diff)
downloadverteco-1.6.tar.gz
modbuslog: flush serial IO buffers on modbus errorv1.6
-rw-r--r--src/modbuslog.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/modbuslog.c b/src/modbuslog.c
index cb509ea..3f9b658 100644
--- a/src/modbuslog.c
+++ b/src/modbuslog.c
@@ -44,6 +44,9 @@
#include <syslog.h>
+#include <termios.h>
+#include <fcntl.h>
+
// handle SIGALRM by resetting it
void minute_check(int signum) {
alarm(60);
@@ -271,6 +274,21 @@ int main(int argc, char *argv[]) {
// back off for 2 secs, increasing by 2 for each
// incorrect reply
sleep(2+retry*2);
+
+ // open serial port file descriptor,
+ // flush IO, write zero-ouput, reflush IO,
+ // close file descriptor
+ int fd = open(modbus_device_address, O_RDWR | O_NOCTTY );
+ if (tcflush(fd, TCIOFLUSH) == 0){
+ syslog(LOG_WARNING, "Flushing [%s] serial IO buffer", modbus_device_address);
+ }
+ if (tcsendbreak(fd, 0) == 0){
+ syslog(LOG_WARNING, "Writing zero-value bits to [%s]", modbus_device_address);
+ }
+ if (tcflush(fd, TCIOFLUSH) == 0){
+ syslog(LOG_WARNING, "Reflushing [%s] serial IO buffer", modbus_device_address);
+ }
+ close(fd);
}
retry++;
} while ((rc == -1) && (retry <= modbus_retry));