From 390556176fefef447eb0eed07cafeece9e279aa2 Mon Sep 17 00:00:00 2001 From: termocontrole <33967393+termocontrole@users.noreply.github.com> Date: Mon, 12 Mar 2018 05:14:22 -0300 Subject: [PATCH] [fix] Modbus RTU sync issues (#32) --- src/comWrapper.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/comWrapper.c b/src/comWrapper.c index b4e5682..3ffd684 100644 --- a/src/comWrapper.c +++ b/src/comWrapper.c @@ -128,21 +128,16 @@ int com_set_interface_attribs(int fd, int speed, int data_bits, int parity_bit, tty.c_cflag &= ~CRTSCTS; /* no hardware flowcontrol */ tty.c_iflag &= ~(IXON | IXOFF | IXANY); /* disable software flow control */ - //tty.c_oflag &= ~OPOST; - //tty.c_cc[VTIME] = 0; - //tty.c_cc[VMIN] = 0; + + //Set an overall timeout of 2 sec/byte + tty.c_cc[VTIME] = 20; + tty.c_cc[VMIN] = 0; -//#if 0 - /* setup for non-canonical mode */ + /* setup for non-canonical mode, based on function cfmakeraw() */ tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); tty.c_oflag &= ~OPOST; - /* fetch bytes as they become available */ -// tty.c_cc[VMIN] = 1; -// tty.c_cc[VTIME] = 1; -//#endif - if (tcsetattr(fd, TCSANOW, &tty) != 0) { printf("Error from tcsetattr: %s\n", strerror(errno)); return -1; @@ -152,7 +147,7 @@ int com_set_interface_attribs(int fd, int speed, int data_bits, int parity_bit, int com_open(const char* pathname) { - return open(pathname, O_RDWR | O_NOCTTY); //| O_NDELAY | O_EXCL); + return open(pathname, O_RDWR | O_NOCTTY); } int com_close(int fd)