Solved

interrupt driven serial communication...

Posted on 1998-08-25
4
586 Views
Last Modified: 2013-12-26
  I am trying to write an interrupt driven serial port program using C, and I was wondering if anyone have amy idea if this is possible. My Unix system supports POSIX termios.h and aio.h, will my answer lies within these two include files?
   Fundamentally, I would like to send a string of commands out of my serial port and proceed with other task. In the background I would like to have an interrupt handler that continously read the in-coming buffer for a full length string return data. I don't want to hang the system on the read process because of the my process is under real-time.
0
Comment
Question by:nickolas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:nickolas
ID: 1293017
Adjusted points to 200
0
 
LVL 2

Expert Comment

by:JYoungman
ID: 1293018
Use select(), or poll(), or pthreads, or asynchronous I/O.

0
 
LVL 2

Expert Comment

by:JYoungman
ID: 1293019
You could also set VMIN and VTIME with the <termios.h> API.

0
 
LVL 3

Accepted Solution

by:
dhm earned 200 total points
ID: 1293020
Under unix, a user-level program never deals directly with interrupts from devices -- the interrupts are handled by a piece of code called a device driver.  The driver can (but doesn't have to) send a signal to the user process using the device.  A user-process signal is similar to a hardware interrupt, but is not necessarily connected to any particular piece of hardware.  Signals can be a pain in the ass to get working properly, and you're probably better off not using them for anything that requires fairly accurate timing or that can't tolerate missed signals.

I'm not aware of any way to do "asynchronous I/O" under unix, assuming JYongman had in mind something like NT's asynch I/O, where you start a read operation and then go off and do something else, and when the read is finished, the system sets a flag for you to check.  (You could easily implement that sort of thing, though, using threads.)  Threads will probably give you the most flexibility in solving your problem, but if you're new to threaded programming, it can be difficult, and you may not need all that flexibility anyway.

You can use select() or poll() to see if there's any data ready to be read, and there's an ioctl() that will return the amount of data you can read immediately (the ioctl command is FIONREAD).  You can use a combination of these to keep from hanging on a read.  These are standard I/O calls that work on any file descriptor (FIONREAD may not work on all files, but it usually works on terminals and serial ports.)

If you want to use termios, then you can play with VMIN and VTIME to control how long a read will delay.  The termios man page is long and confusing, though, and I'm skeptical that things that are hard to describe will actually work properly all the time, so I'd advise trying select() and ioctl() first.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
Folder Comparison 12 56
isEverywhere  challenge 19 91
Adjust the codes 3 63
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question