[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

using select method



Hi All,
I need some help.
Below is a sample code I've been using to try to access and read/write to a serial port using select method.
When I ran this code nothing happens and there is data, lots of it, at the port.
in the code I use both timeout (last arg &tv) and blocking (last arg NULL)
Could anyone give me some advice on this. It'll be greatly appreciated.


        fd_set read_fds;
        struct timeval tv;
        ssize_t retval = 1;
        volatile int sio_res, indx;

        sio_fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
        if(sio_fd < 0) {
                perror(MODEMDEVICE);
                return 0;
        }
        if(ttyclr(sio_fd, TCSANOW, B9600, 1,0) < 0) perror(HERE);
        /* end init serial */

        FD_ZERO(&read_fds);
        FD_SET(sio_fd, &read_fds);
        /* zero timeout return immediately */
        tv.tv_sec = 0;
        tv.tv_usec = 0;
        while(1) {
                toggle_led("0x0");
                FD_ZERO(&read_fds);
                FD_SET(sio_fd, &read_fds);
                usleep(1);

                retval = select(1, &read_fds, NULL, NULL, NULL);
                if(retval < 0) perror(HERE);
                else if(retval == 0) {
                        if(FD_ISSET(sio_fd,&read_fds)) printf("data??\n");
                        printf("  Timeout %d\n ",retval);
//                      usleep(20000);
                } else { }
}

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!




Reply to: