aboutsummaryrefslogtreecommitdiffstats
path: root/src/modbuslog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modbuslog.c')
-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));