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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:30:48+00:00 2026-05-26T18:30:48+00:00

I have a system where I am seeing strange behavior with the serial ports

  • 0

I have a system where I am seeing strange behavior with the serial ports that I don’t expect. I’ve previously seen this on occasion with usb-to-serial adapters, but now I’m seeing it on native serial ports as well, with much greater frequency.

The system is set up to run automated tests and will first perform some tasks that cause a large amount of data to be outputted from the serial device while I do not have the ports open. The device will also reset itself. Only the tx/rx lines are connected. There is no flow control.

After these tasks complete, the testware opens the serial ports and immediately fails because it gets unexpected responses. When I reproduce this, I found that if I open the serial port in a terminal program, I see several kilobytes of old data (that appears to have been sent when the port was closed) immediately flushed out. Once I close this program, I can then run the tests as expected.

What could cause this to happen? How does Linux handle buffering the serial port when the device is closed? If I opened a device, made it send output, and then closed it without reading from it, would this cause the same problem?

  • 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-26T18:30:48+00:00Added an answer on May 26, 2026 at 6:30 pm

    The Linux terminal driver buffers input even if it is not opened. This can be a useful feature, especially if the speed/parity/etc. are set appropriately.

    To replicate the behavior of lesser operating systems, read all pending input from the port as soon as it is open:

    ...
    int fd = open ("/dev/ttyS0", O_RDWR | O_NOCTTY | O_SYNC);
    if (fd < 0)
            exit (1);
    
    set_blocking (fd, 0);   // disable reads blocked when no input ready
    
    char buf [10000];
    int n;
    do {
            n = read (fd, buf, sizeof buf);
    } while (n > 0);
    
    set_blocking (fd, 1);  // enable read blocking (if desired)
    
    ...  // now there is no pending input
    
    
    
    void set_blocking (int fd, int should_block)
    {
            struct termios tty;
            memset (&tty, 0, sizeof tty);
            if (tcgetattr (fd, &tty) != 0)
            {
                    error ("error %d getting term settings set_blocking", errno);
                    return;
            }
    
            tty.c_cc[VMIN]  = should_block ? 1 : 0;
            tty.c_cc[VTIME] = should_block ? 5 : 0; // 0.5 seconds read timeout
    
            if (tcsetattr (fd, TCSANOW, &tty) != 0)
                    error ("error setting term %sblocking", should_block ? "" : "no");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have system here that uses Java JNI to call a function in a
I have a system that needs to send and receive data over an insecure
I have a System.Timers.Timer that increments a counter every 3 seconds. Another thread may
I have a system that combines the best and worst of Java and PHP.
I have a C# COM DLL that calls WMI using the System.Management namespace. The
We have a C# logging class that uses System.Diagnostics.StackTrace and StackFrame to obtain information
I have been seeing errors come back from my application that it's force closing
I have a system (let's call it System A) that allows the user to
I have an instance of System.Type that represents an interface, and I want to
To preface we have a strange requirement that all dialogs must be modeless for

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.