diff --git a/src/RS232_unix.c b/src/RS232_unix.c --- a/src/RS232_unix.c +++ b/src/RS232_unix.c @@ -25,14 +25,14 @@ rs232speed_t rs232cfspeed(unsigned int B rs232port_t rs232open(char* psPortName) { - rs232port_t fd; - fd = (rs232port_t)open(psPortName, O_RDWR | O_NOCTTY | O_NDELAY); - fcntl((int)fd, F_SETFL, 0); - //fd = open(psPortName, O_RDWR | O_NOCTTY); - #ifdef debug - if(fd==-1)printf("can't open Port\n"); - #endif - return fd; + rs232port_t fd; + fd = (rs232port_t)open(psPortName, O_RDWR | O_NOCTTY | O_NDELAY); + fcntl((int)fd, F_SETFL, FNDELAY); + //fd = open(psPortName, O_RDWR | O_NOCTTY); + #ifdef debug + if(fd==-1)printf("can't open Port\n"); + #endif + return fd; } int rs232close(rs232port_t fd) @@ -125,6 +125,10 @@ int rs232setup(rs232port_t fd, int ChSiz { struct termios terminos; tcgetattr(fd, &terminos); + terminos.c_iflag=0; + terminos.c_oflag=0; + terminos.c_cflag=0; + terminos.c_lflag=0; cfsetispeed(&terminos, rs232cfspeed(BaudeRate)); cfsetospeed(&terminos, rs232cfspeed(BaudeRate)); terminos.c_cflag |= (CLOCAL | CREAD); @@ -483,13 +487,16 @@ int rs232saferead(rs232port_t fd,char* d { int read=0; int i=0; - for(i=0;i<100;i++) + for(i=0;i<1000;i++) { read = rs232read((int)fd,data,count); - count -=read; + //printf("read %d bytes\n",read); + if(read==-1)read=0; + count-=read; data+=read; if(count==0) return 0; + usleep(10); } return -1; } @@ -503,6 +510,8 @@ int rs232safewrite(rs232port_t fd,char* for(i=0;i<1000;i++) { written = rs232write((int)fd,data+written,count); + //printf("%d bytes written\n",written); + if(written==-1)written=0; count-=written; data+=written; if(count==0)