October 26, 2016
Hot Topics:

How Palm OS Expands Your Applications: Expansion Manager

  • June 23, 2005
  • By Alex Gusev
  • Send Email »
  • More Articles »

Expansion Manager, to confirm its name, is a layer that manages slot drivers. Actually, it doesn't work with slots directly. Instead, Expansion Manager provides unified APIs to manupilates slots. All specific 'magic is performed by appropriate slot driver implemented as a shared library. Such architecture is similar to VFS Manager (see the previous article ). The next sections will guide you through the stuff available for applications. But, right here I would like to highlight one simple but important thing: Prior to using any functions from Virtual File System Manager or Expansion Manager, your application must verify whether those features are present. This is as easy as a couple of code lines:

UInt32 nValue = 0;
if ( ftrErrNoSuchFeature == FtrGet(sysFileCExpansionMgr,
                                   expFtrIDVersion, &nValue) )
// Nothing to do...
// Check here required minimal Expansion Manager Version

Slot Enumeration and So Forth

As with many other managers, the very first step is usually some kind of enumeration process. Your application needs to know which slots are presented in the system. Hence, the slot number is a base stone in all further operations. The following tiny snippet shows all the required code to obtain available slots:

UInt16 slotRefNum = -1;
UInt32 slotIterator = expIteratorStart;
while (slotIterator != expIteratorStop)
   if ( errNone == (err = ExpSlotEnumerate(&slotRefNum,
                                           &slotIterator)) )
      // slotRefNum to be used later
      // error occured

After the slot number is detected, there are a number of operations you can accomplish. I will start with the simplest one:

Err ExpCardPresent(UInt16 slotRefNum)

This function verifies whether a card is presented into specified slot. errNone indicates success; in other words, the card is in. All other return codes will flag appropriate an error; for example, expErrCardNotPresent.

Your application may need to gather more info about a card in a slot. The following simple function provides this data:

Err ExpCardInfo(UInt16 slotRefNum, ExpCardInfoType *infoP)

A code sample below displays one possible scenario:

/* Excerpt from ExpansionMgr.h
typedef struct ExpCardInfoTag
   // bits for different stuff the card supports
   UInt32 capabilityFlags;
   // Manufacturer, e.g., "Palm", "Motorola", etc...
   Char   manufacturerStr[expCardInfoStringMaxLen+1];
   // Name of product, e.g., "SafeBackup 32MB"
   Char   productStr[expCardInfoStringMaxLen+1];
   // Type of product, e.g., "Backup", "Ethernet", etc.
   Char   deviceClassStr[expCardInfoStringMaxLen+1];
   // Unique identifier for product, e.g., a serial number.
   // Set to "" if no such identifier exists.
   Char   deviceUniqueIDStr[expCardInfoStringMaxLen+1];
ExpCardInfoType, *ExpCardInfoPtr;
ExpCardInfoType CardInfo;
if( errNone == ExpCardInfo(slotRefNum,&CardInfo))
   HostTraceOutputTL(appErrorClass,"Capability: %snManufacturer:
                 %snName: %snClass: %s",
                (const char*)GetCapability(CardInfo.capabilityFlags),
// process error
CString GetCapability(UInt32 capabilityFlags)
   CString sInfo;
   if ( capabilityFlags & expCapabilityHasStorage )
      sInfo += " Has Storage";
   if ( capabilityFlags & expCapabilityReadOnly )
      sInfo += " Read Only";
   if ( capabilityFlags & expCapabilitySerial )
      sInfo += " Serial Interface";
   return sInfo;

As you can see, the received struct contains important info regarding card capabilities and class, so you always will be able to determine what your application can do with this particular storage or whatever it is.

If the expansion card supports simple serial interface, you can obtain a creator ID to use it later with Serial I/O API calling:

Err ExpCardGetSerialPort(UInt16 slotRefNum, UInt32 *portP)

A typical usage is as follows:

UInt32 port;
if ( errNone == ExpCardGetSerialPort(slotRefNum, &port) )
    UInt16 newPortId;
    err = SrmOpen (port, 19200, newPortId);

In Palm OS 6 Cobalt, ExpCardGetSerialPort and related stuff were deleted, so yoo should check which OS version you're going to support in your applications.

Page 1 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel