locked
Read time is not working RRS feed

  • Question

  • Hi,

    I am having the following code in c for reading from UART port.

    struct sigaction saio;

    #define MAX_UARTS 3

    int dataReady[MAX_UARTS];

    int fd[MAX_UARTS];

    int fdUart;

    int uartCount = 0;

    void uart_handler0() {

    dataReady[0] = TRUE;

    }

    void uart_handler1() {

    dataReady[1] = TRUE;

    }

    int ReadData(char*port, intbuadRate ) {

    /* Set up the  serial port  */

    structtermios newtio;

    /* open the device to be non-blocking (read will return immediatly) */

    fdUart = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);

    if(fdUart <0) {

    printf("ERROR: Unable to open the file\n");

    }

    /* install the signal handler before making the device asynchronous */

    switch(uartCount){

    case0:

    saio.sa_handler = uart_handler0;

    break;

    case1:

    saio.sa_handler = uart_handler1;

    break;

    }

    saio.sa_flags = 0;

    saio.sa_restorer = NULL;

    sigaction(SIGIO, &saio, NULL);

    /* allow the process to receive SIGIO */


    fcntl(fdUart, F_SETOWN, getpid());

    /* Make the file descriptor asynchronous (the manual page says only O_APPEND and O_NONBLOCK, will work with F_SETFL...) */


    fcntl(fdUart, F_SETFL, FASYNC);

    newtio.c_cflag = buadRate | CRTSCTS | CS8 | CLOCAL | CREAD;

    newtio.c_iflag = IGNPAR | ICRNL;

    newtio.c_oflag = 0;

    newtio.c_lflag = ICANON;

    newtio.c_cc[VMIN]=0;

    newtio.c_cc[VTIME]=0;

    tcflush(fdUart, TCIFLUSH);

    tcsetattr(fdUart, TCSANOW, &newtio);

    int res;

    res = read(fdUart, buff, 1000);

    if(res<0)

    {

    printf("failed to read\n");

    returnFAILURE;

    }

    else

    {

    buff[res] = '\0';

    returnSUCCESS;

    }

    returnFAILURE;

    }

    This is my code.

    the code underlined is for setting read wait.

    i set vmin to 0 even no data received it has to be terminated.

    and vmax to 5 to make to read to wait for 5 seconds.

    but the read not even terminates and still running.

    Thank you in advance :)

    Tuesday, April 9, 2013 12:06 PM

All replies

  • Well this is Unix/Linux code, that you are asking about on a windows forum that is dedicated to driver testing and Windows certification of drivers.  So I suspect you won't be getting an answer here.  I believe there are packages that will support these calls on Windows, but at least tell people what package, what version of the OS and other things so we have a basis to start to help you.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Friday, April 12, 2013 12:39 AM
  • Thank you Don...

    I usually got some replies to some questions regarding C# in msdn forum, so I posted the questions here.

    As, this is related to Ethernet, I thought as hardware.. :)

    Thanks for your reply...

    I will search for the packages...


    Friday, May 10, 2013 12:55 PM