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.
Interrupt-driven serial communications (continued)

Next we call SerPrimeWakeupHandler to tell when to call the callback. This sets the number of characters to receive after which the callback will be called. In the example, I want to process characters even if only one comes in, so I set to call me after the first character.

If you were reading in fixed-length blocks, you could set the "prime count" to the size of the block -- then you'd know you have received at least a full block when your handler is called.

The Wakeup Handler Awakens
When the "prime count" number of characters has been received, the serial port's ISR (interrupt service routine) will call your wakeup handler callback. It will disable further callbacks so you needn't worry about reentrancy (you will need to re-enable the handler again later). It calls your handler with a single argument -- the reference number that you set in SerSetWakeupHandler. If you had multiple serial ports and used the same callback handler for all of them, you'd use this number to distinguish between the ports.

"Warning: note that you're operating in an interrupt-routine context!"

Warning: note that you're operating in an interrupt-routine context! You can do very little at this time! In fact, the only Palm OS API that's safe is to call is EvtEnqueueKey. No other APIs are interrupt-safe.

EvtEnqueueKey inserts a "key down" event into the event queue. It could enqueue a normal key (as such things as the Fitaly or Jot keyboards do) or it could use a special command key (such as lowBatteryChr, menuChr or ronamaticChr), as some of the Palm internal routines do. We'll use a special command key like the OS does, but we'll define our own. As it turns out, all the special keys that Palm uses have a "virtual key" of zero, so we can simply use a different virtual key code. In the example, I use an ASCII code of 'S', a virtual key of 0x01, and the commandKeyMask modifier.

After calling EvtEnqueueKey, the wakeup handler returns to the serial ISR.

The Event Loop Awakens
The key down event that we just posted causes the event loop to wake up -- with a keyDownEvent, naturally.

We could let the event be handled as a normal key-down event; typically this is in the form handler. But I wanted to be sure that the normal OS routines never see our special command key -- just in case they (or a future machine) would misinterpret it. So I created a special event handler, SerialHandleEvent. This looks for key-down events with our custom key. When it finds one, it processes the received serial characters. The event loop calls SerialHandleEvent before it calls any of the other handlers.

Getting the Received Characters
In December's version, we used SerReceiveCheck and SerReceive10 (the Palm OS version 1.0 compatible API) to get the characters that came in the serial port.

There's an anomaly with the wakeup handler -- it seems to break SerReceive and SerReceive10; neither works properly when a wakeup handler is set. Because the wakeup handler is undocumented, I don't know if this is intentional or not -- I just know they haven't worked when I've tried them.


« Previous  ·  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 defenders have spoken
David Gewirtz Online: CNN commentary and analysis
DominoPower: Application development, William Shatner, and the origin of the universe
OutlookPower: More about disappearing text
-- Advertisement --

NO HASSLE PHOTO PRINTING, SHARING, AND STORAGE -- AS LOW AS $2.54 PER MONTH
Discover an easier way to share, print and manage your photos online! Get your own online photo album site for sharing photos, as well as easy-to-use editing tools to make sure your photos look their very best. You can even order high quality prints directly from your album -- and have them delivered right to your door!

Best of all, you can also get login-free photo sharing at your personal domain name (if you have one), so your friends and family don't have to hassle with signing up or logging in just to view your pictures. It's the perfect solution for sharing, printing and storing all your favorite images!

And it's only from The Duck! Tap here to get started.

-- Advertisement --

SECURE YOUR SITE WITH AN IRONCLAD SSL CERTIFICATE
An IronClad SSL Certificate helps you build an impenetrable fortress around your customer's credit card information. IronClad SSL Certificates are:

  • Fully validated
  • Up to 256-bit encryption
  • Up to 10 years validity
  • Stringent authentication
  • Around-the-clock customer support

Build trust. Protect your customers. Grow your online business.

Tap here now and be IronClad with SSL tonight.

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