Find the answer to your Linux question:
Results 1 to 4 of 4
I use serial port. I get serial EAGAIN error. I open serial port with below settings. do I have any error with settings. Thanks. static int fd=-1; bool openPort(int baudrate, ...
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    2

    I get serial port EAGAIN Error

    I use serial port. I get serial EAGAIN error. I open serial port with below settings.

    do I have any error with settings.

    Thanks.



    static int fd=-1;

    bool openPort(int baudrate, const char * ThePort) {

    unsigned long BAUD;
    struct termios port_settings;
    fd = open(ThePort, O_RDWR | O_NOCTTY | O_NDELAY );

    tcgetattr(fd, &port_settings);

    if (fd == -1) // if open is unsucessful
    {
    //perror("open_port: Unable to open /dev/ttyS0 - ");
    printf("open_port: Unable to open /dev/tty0. \n");
    } else {

    fcntl(fd, F_SETFL, FNDELAY);
    printf("port is open.\n");
    }

    switch (baudrate) {
    case 115200:
    BAUD = B115200;
    break;
    case 57600:
    BAUD = B57600;
    break;
    case 38400:
    BAUD = B38400;
    break;
    case 9600:
    BAUD = B9600;
    break;
    default:
    BAUD = B38400;
    break;
    }

    // structure to store the port settings in

    cfsetispeed(&port_settings, BAUD); // set baud rates
    cfsetospeed(&port_settings, BAUD);




    port_settings.c_cc[VMIN] = 1;
    port_settings.c_cc[VTIME] = 0;


    port_settings.c_iflag = IGNPAR | IUCLC;
    port_settings.c_oflag = 0;
    port_settings.c_lflag = 0;
    port_settings.c_cflag |= (CLOCAL | CREAD);
    port_settings.c_cflag &= ~(CSIZE | PARENB);
    port_settings.c_cflag &= ~CSTOPB;
    port_settings.c_cflag |= CS8;

    tcsetattr(fd, TCSANOW, &port_settings); // apply the settings to the port
    return (fd);

    }

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Please show the code where you are getting the EAGAIN error. What it means depends upon the context you are in at the time and what you are doing. For example, in a read() operation it means that the socket/port was in a non-blocking state and that there was no data available to read. In such a case, it isn't an error as such, but more of an advisory.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    136
    In common sense EAGAIN means that kernel tells you "Hey, dude, there's nothing to do, try again later!" I suggest you try to read from a port and nothing writing data to it at the moment.

  4. #4
    Just Joined!
    Join Date
    Apr 2010
    Posts
    2
    Quote Originally Posted by Rubberman View Post
    Please show the code where you are getting the EAGAIN error. What it means depends upon the context you are in at the time and what you are doing. For example, in a read() operation it means that the socket/port was in a non-blocking state and that there was no data available to read. In such a case, it isn't an error as such, but more of an advisory.

    I get this error in below code


    for (index = 0;; index++) {

    int iIn = read(fd, buffer + index, 1);

    //buffer[iIn-1] = 0x00;

    if (iIn < 0) {
    if (errno == EAGAIN) {
    printf("SERIAL EAGAIN ERROR\n"); /
    return 0;
    } else {
    printf("SERIAL read error %d %s\n", errno, strerror(errno));
    return 0;
    }
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...