Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

interrupt driven serial communication...

Posted on 1998-08-25
4
Medium Priority
?
589 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 400 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.
Suggested Courses

972 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