Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 815457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:41:12+00:00 2026-05-15T01:41:12+00:00

I want to use serial com port for communication and I want to implement

  • 0

I want to use serial com port for communication and I want to implement a timeout every time I call the read() function call.

int filedesc = open( "dev/ttyS0", O_RDWR );

read( filedesc, buff, len );

EDIT:

I’m using Linux OS. How to implement using select function call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:41:13+00:00Added an answer on May 15, 2026 at 1:41 am

    select()
    takes 5 parameters, first the highest file descriptor + 1, then a fd_set for read, one for write and one for exceptions. The last parameter is a struct timeval, used for timeout. It return -1 on error, 0 on timeout or the number of file descriptors in the sets that are set.

    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <sys/select.h>
    
    int main(void)
    {
      fd_set set;
      struct timeval timeout;
      int rv;
      char buff[100];
      int len = 100;
      int filedesc = open( "dev/ttyS0", O_RDWR );
    
      FD_ZERO(&set); /* clear the set */
      FD_SET(filedesc, &set); /* add our file descriptor to the set */
    
      timeout.tv_sec = 0;
      timeout.tv_usec = 10000;
    
      rv = select(filedesc + 1, &set, NULL, NULL, &timeout);
      if(rv == -1)
        perror("select"); /* an error accured */
      else if(rv == 0)
        printf("timeout"); /* a timeout occured */
      else
        read( filedesc, buff, len ); /* there was data to read */
      close(filedesc);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying access an extern device via a serial port and want to use
I want use javascript setInterval function to achieve a box rotate animate effect, I
I am using serial port communications in my ASP.NET webform application: private bool sendSMS(int
I am using Erlang for driving robot using wireless serial communication. I want to
My collegues don't like auto generated int serial number by database and want to
I want to read messages sent from an Arduino via the FTDI (serial) interface
I have a hardware here, wich communicates over serial port. I use MS Visual
I'm learning how to use Boost:asio library with Serial Port. I wrote some code
My only way of communication with my embedded device is a serial port. By
I want to read the name and the serial number of my hard drives.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.