Search PalmPower's 487 Palm-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
PROGRAMMING POWER
Interrupt-driven serial communications
By Alan Jay Weiner

In my December 1998 column, I introduced you to the Palm device's serial port. That version of SerialEcho used polling -- it would check every now and then for received characters. As I said then, polling is inefficient; it wastes processor time (and therefore battery power) to check and find that nothing has been received. In some programs, the time wasted checking could be used for other processing.

There's a better way. When your phone rings, you answer it; interrupting what you're doing. After the call, you can return to what you were doing before. We can do the same in the Palm device by using some undocumented, but well established APIs (Applications Programming Interfaces).

The low-level serial drivers actually do use interrupts. When the hardware is able to transmit a character or has received a character, it pulls an interrupt, causing the processor to stop what it's doing and service that interrupt -- either receiving or sending a character.

Unfortunately, the application is forced to poll for received characters.

This month I'll show you how to set up a callback when characters are received on the serial port. This allows the program to sit idle or do other processing while nothing's waiting to be read in.

If you want to follow along with the actual code, open a new browser window and point your browser at http://www.component-net.com/pp-extras/serial2.html.

What's a callback?
When you go to a hotel and ask the desk for a morning wakeup call, that's a callback. Software callbacks are the same thing -- you tell the operating system the address of the callback routine, then later when the conditions are right the operating system calls that routine. In this case, the callback will be executed when characters have come in the serial port. We already use callbacks to set the form event handler. When our application calls FrmSetEventHandler (usually in ApplicationHandleEvent or some similarly named routine) it tells Palm OS the address of the particular form's event handler. Then when form events occur, and your event loop calls FrmDispatchEvent, guess where it goes? Yup: the form event handler. See? It's just a callback.

Use the Source, Luke!
Hidden in the SDK's header files are many gems of information. There are numerous definitions and API prototypes that don't appear in the documentation. Over time, some of these have become semi-documented by various people who asked questions and figured out how they worked.


1  ·  2  ·  3  ·  4  ·  Next »
Other articles you might like
Home > Phones and PDAs > Palm and Treo > Programming (24 articles)
   How PDA software is born
   Program with Simplicity
   Kinectivity 2.0 brings enterprise application developers new tools
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Other PalmPower Articles
Palm gets up to date with new Tungsten family of handhelds
Create handwritten email with riteMail
Presenter-to-Go puts PowerPoint presentations on your Palm OS handheld
Looking for the cutting edge
Gain remote access to databases and PLCs
PalmSource Open House showcases what's new in the Palm community
Analysis: handheld market share
More from the ZATZ journals
Computing Unplugged: The iPad: Apple's latest heartbreaker
David Gewirtz Online: CNN commentary and analysis
DominoPower: Lotusphere 2010: mobility and collaboration
OutlookPower: Running auto-respond rules when Outlook is closed
-- Advertisement --

BLOGGING AND PODCASTING WITH ONE EASY-TO-USE TOOL
Now you can publish your thoughts, opinions, and comments in your own blog or podcast.<p />

  • Supports multiple authors and multiple blogs or podcasts.
  • Generate and publish RSS feeds for iTunes and other directories.
  • Post photos, images or animations.
  • Get feedback and have conversations with visitors to your site. <p />

Personalize your blog or podcast with your own unique domain name -- or integrate it with your existing site by setting it up as a subdomain.

Tap here and get blogging or podcasting within minutes.

-- Advertisement --

Sent Items Organizer
When you need to file your sent email into their proper folders based on keywords or who it's to. It's also perfect for shared mailboxes.

It also adds a "Send And File" toolbar button while you're composing (similar to the way Lotus Notes used to work) for quick and easy filing.

Find out more!

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login