AnsweredAssumed Answered

read(), termios VMIN,VTIME no effect

Question asked by feucom on Jul 23, 2012
Latest reply on Jul 27, 2012 by feucom



read() seams to ignore termios settings VMIN/VTIME. I try to adjust the timeout with VMIN and VTIME, but it has no effect, even VMIN=0,VTIME=0. If no bytes no bytes arrive I would expect that read() returns at least NULL but it returns nothing and stays for infinity in waiting loop. Could you tell me what wrong in my settings, please?






HW : stamp board BF537



int open_port(char *tty_port)


    int fd; // file description for the serial port

    char path[20] = "/dev/";

    strcat(path, tty_port);


    fd = open(path, O_RDWR | O_NOCTTY | O_NDELAY);


    if(fd < 0) // if open is unsucessful


        perror("open_port: Unable to open /dev/ttyBF1 - ");

        printf("open_port: Unable to open /dev/,%s \n",tty_port);




        fcntl(fd, F_SETFL, 0);                //normal blocking behavior (already done by O_NDELAY)

        printf("port, %d, is open.\n", fd);







int configure_port(int fd)      // configure the port


    struct termios tty_config;

    if (tcgetattr(fd, &tty_config)<0) printf( "failed to get initial config\n" );


          tty_config.c_cflag &= ~PARENB;    //parity enable

          tty_config.c_cflag &= ~CSTOPB;    //2 stopbit otherwise one

          tty_config.c_cflag &= ~CSIZE;        //bitmask for data bit

          tty_config.c_cflag &= ~CRTSCTS;    //hardware fc

          tty_config.c_cflag |= CS8;        //8 bit

          tty_config.c_cflag |= CREAD;        // rx enable

          tty_config.c_cflag |= CLOCAL;        //local line

//      tty_config.c_cflag |= HUPCL;        //hang upon last close


          tty_config.c_lflag &= ~ICANON;    //canonical

          tty_config.c_lflag &= ~ECHOCTL;    //echo NL

          tty_config.c_lflag &= ~ECHOKE;    //BS-SP-BS entier line lin kill

          tty_config.c_lflag &= ~ECHOK;        //echo NL after NL kill

          tty_config.c_lflag &= ~ECHO;        //echo

          tty_config.c_lflag &= ~ECHOE;        //echo erase char

          tty_config.c_lflag &= ~ISIG;        //signature

          tty_config.c_lflag &= ~IEXTEN;    //enable ext. function


          tty_config.c_iflag &= ~IXON;        //outgoing soft FC

          tty_config.c_iflag &= ~IXOFF;        //incoming soft FC

          tty_config.c_iflag &= ~IXANY;        //allow any char to star flowcontrol

          tty_config.c_iflag &= ~ICRNL;        //map CR to NL

          tty_config.c_iflag &= ~INLCR;        //map NL to CR

          tty_config.c_iflag |=  IGNCR;        //ignore CG


          tty_config.c_oflag &= ~OPOST;        //postprocess output

          tty_config.c_oflag &= ~ONLCR;        //map NL to CR-NL


          tty_config.c_cc[VMIN]  = 2;                    //min number of bytes to read

          tty_config.c_cc[VTIME] = 50;                    //timeout 10 *1/10 = 1 sec


//              set ttyflags "-icrnl -ixon igncr -opost -onlcr -isig -icanon -iexten -echo -echoe -echok

//           *                -echoke -hupcl -echoctl -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts min 1 time 0"


    if (cfsetispeed(&tty_config, B9600)<0) printf( "failed to set in put baud rate\n" );

    if (cfsetospeed(&tty_config, B9600)<0) printf( "failed to set output baud rate\n" );


    if (tcsetattr(fd, TCSANOW, &tty_config)<0)printf( "failed to apply config\n" );