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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:40:59+00:00 2026-06-01T17:40:59+00:00

To start off, I’m having trouble getting my serial device to generate a SIGIO

  • 0

To start off, I’m having trouble getting my serial device to generate a SIGIO when data is ready to be read.

I am trying to write a simple serial interface to communicate to a micro using a usb to serial adapter. I’d like to keep this interface as similar to one you would find in a micro (interrupt driven, using callbacks) and so I decided to go the way of catching a SIGIO signal instead of using a separate thread or constant non-blocking serial reads. Here is my initialization code (most of it will look familiar from the various asynchronous serial tutorials):

int mcs = TIOCM_RTS;
ttyDev = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK);

if (!ttyDev)
{
  printf("couldn't open serial device");
  return NULL;
}

//create signal handler
byteAction.sa_handler = byteCallback;
sigemptyset(&byteAction.sa_mask); //sa_mask = 0
byteAction.sa_flags = SA_RESTART;
sigaction(SIGPOLL, &byteAction, NULL);

//Allow process to detect SIGIO
fcntl(ttyDev, F_SETOWN, getpid());
fcntl(ttyDev, F_SETFL, FASYNC); //make async
fcntl(ttyDev, F_SETFL, FNDELAY);  //non blocking reads


tcgetattr(ttyDev, &oldtio); //backup current settings
newtio.c_cflag = getBaud(baudrate) | CS8 | CLOCAL | CREAD;
newtio.c_cflag &= ~CRTSCTS; //disable hw flow control
newtio.c_iflag &= ~(IXON | IXOFF | IXANY); //disable flow control
newtio.c_iflag |= IGNPAR; //ignore parity
newtio.c_oflag = 0;
newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw mode
newtio.c_cc[VMIN] = 1; 
newtio.c_cc[VTIME] = 0;
cfsetspeed(&newtio, getBaud(baudrate));
tcflush(ttyDev, TCIFLUSH);
tcsetattr(ttyDev, TCSANOW, &newtio);

//clear RTS
ioctl(ttyDev, TIOCMBIC, &mcs);

byteCallback is my signal handler. I already verified that it works by sending the process a signal manually. The micro I am communicating with does not support any sort of flow control, so that is disabled. I’ve verified that I can read and write from the device by using the standard read/write system calls.

The problem is that when data comes in, the signal handler doesn’t get called. I suspect it is because SIGIO is only generated when a CR or end of line character is received. Since this is completely raw mode and no such character is being sent, no SIGIO is being generated. At the moment I have only tried this on OSX, but ideally the same code would work on linux as well.

Any help would be appreciated. I’ve searched quite a bit and people always end up suggesting to just use select() or another method. It’s become almost a challenge and I’m not ready to give up just yet.

Thanks.

  • 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-06-01T17:41:00+00:00Added an answer on June 1, 2026 at 5:41 pm

    Generation of SIGIO definitely has nothing to do with CR/NL. Your problem is that right after you set the FASYNC flag, you cleared it:

    fcntl(ttyDev, F_SETFL, FASYNC); //make async
    fcntl(ttyDev, F_SETFL, FNDELAY);  //non blocking reads AND CLEAR FASYNC FLAG
    

    What you should be doing is:

    fcntl(ttyDev, F_SETFL, O_ASYNC|O_NONBLOCK);
    

    or preferably (to avoid clearing any other flags that may have already been set):

    fcntl(ttyDev, F_SETFL, O_ASYNC|O_NONBLOCK|fcntl(ttyDev, F_GETFL));
    

    Note that I also took the liberty of replacing the weird nonstandard flag names you were using with the corresponding standard names. 🙂

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

Sidebar

Related Questions

To start off, this really isn't CodeIgniter specific. I'm having trouble grasping an idea,
I am getting started with my first MVC project and want to start off
I'm trying to start off using FBJS, and I can't figure this out. The
I'm trying to start off a as3.0 project with nothing in the maintimline, I
I'm trying to create a bookmarklet that will start off an AJAX call to
First let me start off by saying I read on here a lot and
to start off, I know C++, C#, Python, some Ruby, and basic Javascript. Anyway,
Ok so to start off, I'm not using any sort of web service. Right
I need start off with code because I am not sure what terminology to
Let me start off by saying I don't want to print only the duplicate

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.