Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

interrupt driven serial communication...

Posted on 1998-08-25
4
Medium Priority
?
588 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 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 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