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 1003555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:59:55+00:00 2026-05-16T07:59:55+00:00

I am writing a C program that will read and write from/to a serial

  • 0

I am writing a C program that will read and write from/to a serial port. Each write will be followed by a read which will contain data based on the write. I will have about 16 different writes to perform, each followed by a read.

I am still new to serial programming and am trying to determine how to approach this. Should the program block during each write/read (basically having a big while(1) loop of writes and reads)?

Is it possible to have one thread sending writes while another thread performs the reads? Can a callback be created for allowing a thread to know when data is available to be read from the serial port?

Thanks for the help.

Edit:

OS: Linux

  • 1 1 Answer
  • 1 View
  • 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-16T07:59:55+00:00Added an answer on May 16, 2026 at 7:59 am

    It sounds like a simple loop with a read and a write will be enough. If you want more control (like writing a keep-alive after X seconds of no input) use select or poll; they allow you to “sense” if data is available, so a read will not block (however, you should still read non-blocking in case something happens between the select and the read). Multithreading doesn’t make sense in this case.

    select and poll also allow you to test if writing will block; again, write non-blocking just to be sure. You generally don’t want your process to be hanging in some blocking system call, ever, apart from select or poll, that is. (at least, I don’t)

    Use ioctl to set various parameters on the serial line. Use

    $ strace -o /tmp/strace.minicom -f minicom
    

    to launch minicom (or any other terminal program) and see what they do to get things working, if you’re stuck. And as always, see man select/poll/read/ioctl for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program in C# that will need to store a few Data
I am contemplating writing a program that will move some newly created dirs to
I'm a writing a program that will determine the number of lines, characters, and
I'm writing a program that sends an array through a function (upperhess) that will
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
I am writing an HTML program that will be accessed by over 500 people
I am writing a program, for homework, that will add 2 8-bit binary numbers.
Im writing a program that should read input via stdin, so I have the
I am writing a program that needs to read a set of records that
I'm trying to create a word sorting program that will read the words in

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.