diff --git a/userial/ds9097/linuxlnk.c b/userial/ds9097/linuxlnk.c index 3cdd2ef..309fc1f 100644 --- a/userial/ds9097/linuxlnk.c +++ b/userial/ds9097/linuxlnk.c @@ -185,15 +185,28 @@ SMALLINT owTouchReset(int portnum) cfsetispeed(&term[portnum], B115200); cfsetospeed(&term[portnum], B115200); - /* set to 6 data bits */ - term[portnum].c_cflag |= CS6; + /* set to 6 data bits with fallback to 8 if rejected */ + term[portnum].c_cflag &= ~CSIZE; + term[portnum].c_cflag |= CS6; if (tcsetattr(fd[portnum], TCSANOW, &term[portnum] ) < 0 ) { - OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); - perror("Reset: Error with tcsetattr 2"); - close(fd[portnum]); - return FALSE; + /* CS6 failed, try CS8 fallback for modern kernels/drivers */ + if (errno == EINVAL) { + term[portnum].c_cflag &= ~CSIZE; + term[portnum].c_cflag |= CS8; + if (tcsetattr(fd[portnum], TCSANOW, &term[portnum] ) < 0 ) { + OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); + perror("Reset: Error with tcsetattr 2 (CS6/CS8 fallback failed)"); + close(fd[portnum]); + return FALSE; + } + } else { + OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); + perror("Reset: Error with tcsetattr 2"); + close(fd[portnum]); + return FALSE; + } } return stat; diff --git a/userial/ds9097/linuxses.c b/userial/ds9097/linuxses.c index 182c4eb..87eda85 100644 --- a/userial/ds9097/linuxses.c +++ b/userial/ds9097/linuxses.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -94,6 +95,7 @@ SMALLINT owAcquire(int portnum, char *port_zstr) term[portnum].c_cc[VTIME] = 0; /* 6 data bits, Receiver enabled, Hangup, Dont change "owner" */ + /* Try CS6 first with fallback to CS8 for modern kernels */ term[portnum].c_cflag |= CS6 | CREAD | HUPCL | CLOCAL; /* Set input and output speed to 115.2k */ @@ -103,10 +105,22 @@ SMALLINT owAcquire(int portnum, char *port_zstr) /* set the attributes */ if(tcsetattr(fd[portnum], TCSANOW, &term[portnum]) < 0 ) { - OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); - perror("owAcquire: failed to set attributes"); - close(fd[portnum]); - return FALSE; + /* CS6 failed, try CS8 fallback for modern kernels/drivers */ + if (errno == EINVAL) { + term[portnum].c_cflag &= ~CSIZE; + term[portnum].c_cflag |= CS8 | CREAD | HUPCL | CLOCAL; + if (tcsetattr(fd[portnum], TCSANOW, &term[portnum]) < 0 ) { + OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); + perror("owAcquire: failed to set attributes (CS6/CS8 fallback failed)"); + close(fd[portnum]); + return FALSE; + } + } else { + OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED); + perror("owAcquire: failed to set attributes"); + close(fd[portnum]); + return FALSE; + } } /* Flush the input and output buffers */