Solved

interrupt driven serial communication...

Posted on 1998-08-25
4
583 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 101
zeroFront challenge 7 114
Message not shown 5 67
How do I get Window Title of all opened process? 4 15
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

820 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