# HG changeset patch # User jeandet@pc-de-jeandet3.lab-lpp.local # Date 2012-03-22 15:52:07 # Node ID c194258da26ab33c26130be4138ba160bfe08167 # Parent ffb9425c0576533cec0994051f023a8b0267291a Added RTS and CTS signal handing, saffer read and write functions. Changed to 2.0.0 version! diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.67]) -AC_INIT([librs232],[0.1.0],[alexis.jeandet@lpp.polytechnique.fr],[rs232],[http://www.lpp.fr]) +AC_INIT([librs232],[2.0.0],[alexis.jeandet@lpp.polytechnique.fr],[rs232],[http://www.lpp.fr]) AM_INIT_AUTOMAKE([1.10 -Wall foreign]) AC_CONFIG_MACRO_DIR([m4]) # Checks for programs. @@ -18,10 +18,10 @@ AM_PROG_LIBTOOL # Checks for libraries. # Checks for header files. -AC_CHECK_HEADERS([stdio.h string.h fcntl.h errno.h unistd.h termios.h windows.h]) +AC_CHECK_HEADERS([stdio.h string.h fcntl.h errno.h unistd.h termios.h termio.h windows.h]) -AC_SUBST([RS232_SO_VERSION], [1:2:0]) -AC_SUBST([RS232_API_VERSION], [1.0]) +AC_SUBST([RS232_SO_VERSION], [2:0:0]) +AC_SUBST([RS232_API_VERSION], [2.0]) # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. diff --git a/src/RS232.h b/src/RS232.h --- a/src/RS232.h +++ b/src/RS232.h @@ -36,6 +36,12 @@ rs232extern int rs232setparity(rs232port rs232extern int rs232setnbstop(rs232port_t fd, rs232stop NbStop); rs232extern int rs232setcsize(rs232port_t fd, int ChSize); rs232extern int rs232setbaudrate(rs232port_t fd, int baudrate); +rs232extern int rs232setRTS(rs232port_t fd); +rs232extern int rs232clearRTS(rs232port_t fd); +rs232extern int rs232setDTR(rs232port_t fd); +rs232extern int rs232clearDTR(rs232port_t fd); +rs232extern int rs232saferead(rs232port_t fd,char* data,int count ); +rs232extern int rs232safewrite(rs232port_t fd,char* data,int count); #endif diff --git a/src/RS232_unix.c b/src/RS232_unix.c --- a/src/RS232_unix.c +++ b/src/RS232_unix.c @@ -7,6 +7,9 @@ #ifdef HAVE_TERMIOS_H #include #endif +#ifdef HAVE_TERMIO_H + #include +#endif #include "RS232.h" #ifdef HAVE_WINDOWS_H @@ -95,6 +98,8 @@ int rs232setparity(rs232port_t fd, rs232 { struct termios terminos; tcgetattr(fd, &terminos); + terminos.c_cflag &= ~PARENB; + terminos.c_cflag &= ~PARODD; switch(Parity) { case rs232parityNo: @@ -152,6 +157,7 @@ int rs232setcsize(rs232port_t fd, int Ch { struct termios terminos; tcgetattr(fd, &terminos); + terminos.c_cflag &= ~CSIZE; switch(ChSize) { case 5: @@ -240,21 +246,25 @@ int rs232cfparity(int fd, struct termios } else { + terminos->c_cflag &= ~PARENB; + terminos->c_cflag &= ~PARODD; switch(Parity) { case rs232parityNo: - terminos->c_cflag &= Parity; + terminos->c_cflag &= ~PARENB; + terminos->c_cflag &= ~PARODD; break; case rs232parityOdd: - terminos->c_cflag &= ~PARENB; - terminos->c_cflag |= Parity; + terminos->c_cflag |= PARENB; + terminos->c_cflag |= PARODD; break; case rs232parityEven: - terminos->c_cflag &= ~PARENB; - terminos->c_cflag |= Parity; + terminos->c_cflag |= PARENB; + terminos->c_cflag &= ~PARODD; break; default: terminos->c_cflag &= ~PARENB; + terminos->c_cflag &= ~PARODD; break; } return 0; @@ -291,6 +301,7 @@ int rs232cfcsize(int fd, struct termios } else { + terminos->c_cflag &= ~CSIZE; switch(ChSize) { case 5: @@ -338,6 +349,90 @@ int rs232read(rs232port_t fd,char *psRea } + +int rs232setRTS(rs232port_t fd) +{ + int status; + ioctl(fd, TIOCMGET, &status); + status &= ~TIOCM_RTS; + if (ioctl(fd, TIOCMSET, &status)) + { + return -1; + } + return 0; +} + +int rs232clearRTS(rs232port_t fd) +{ + int status; + ioctl(fd, TIOCMGET, &status); + status |= TIOCM_RTS; + if (ioctl(fd, TIOCMSET, &status)) + { + return -1; + } + return 0; +} + +int rs232setDTR(rs232port_t fd) +{ + int status; + ioctl(fd, TIOCMGET, &status); + status &= ~TIOCM_DTR; + if (ioctl(fd, TIOCMSET, &status)) + { + return -1; + } + return 0; +} + + +int rs232clearDTR(rs232port_t fd) +{ + int status; + ioctl(fd, TIOCMGET, &status); + status |= TIOCM_DTR; + if (ioctl(fd, TIOCMSET, &status)) + { + return -1; + } + return 0; +} + + + +int rs232saferead(rs232port_t fd,char* data,int count ) +{ + int read=0; + int i=0; + for(i=0;i<100;i++) + { + read = rs232read(fd,data,count); + count -=read; + data+=read; + if(count==0) + return 0; + } + return -1; +} + + + +int rs232safewrite(rs232port_t fd,char* data,int count) +{ + int written=0; + int i=0; + for(i=0;i<1000;i++) + { + written = rs232write(fd,data+written,count); + count-=written; + data+=written; + if(count==0) + return 0; + } + return -1; +} + #endif #endif //#ifdef HAVE_TERMIOS_H diff --git a/src/RS232_win.c b/src/RS232_win.c --- a/src/RS232_win.c +++ b/src/RS232_win.c @@ -220,4 +220,68 @@ int rs232read(rs232port_t fd,char *psRea } +int rs232saferead(rs232port_t fd,char* data,int count ) +{ + int read=0; + int i=0; + for(i=0;i<100;i++) + { + read = rs232read(fd,data,count); + count -=read; + data+=read; + if(count==0) + return 0; + } + return -1; +} + + + +int rs232safewrite(rs232port_t fd,char* data,int count) +{ + int written=0; + int i=0; + for(i=0;i<1000;i++) + { + written = rs232write(fd,data+written,count); + count-=written; + data+=written; + if(count==0) + return 0; + } + return -1; +} + + +int rs232setRTS(rs232port_t fd) +{ + if(EscapeCommFunction(fd, SETRTS)) + return 0; + return -1; +} + +int rs232clearRTS(rs232port_t fd) +{ + if(EscapeCommFunction(fd, CLRRTS)) + return 0; + return -1; +} + +int rs232setDTR(rs232port_t fd) +{ + if(EscapeCommFunction(fd, SETDTR)) + return 0; + return -1; +} + + +int rs232clearDTR(rs232port_t fd) +{ + if(EscapeCommFunction(fd, CLRDTR)) + return 0; + return -1; +} + + + #endif //#ifdef HAVE_WINDOWS_H diff --git a/src/rs232config.h.in b/src/rs232config.h.in old mode 100755 new mode 100644 --- a/src/rs232config.h.in +++ b/src/rs232config.h.in @@ -39,6 +39,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_TERMIOS_H +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMIO_H + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H