Tech Note 37: Using the DevInfoLib Library

May 01, 2008

© NSB Corporation. All rights reserved.

This library was contributed by Douglas Handy.

Contents:

    Introduction
    Function Index and Quick Reference
    Function Reference

Introduction:

This library provides some basic information on the device on which it is running.

In order to use the DevInfoLib Library, the library must be loaded using the NSBasic LoadLibrary statement. This statement should be located in the program's Startup code so that the functions will be available throughout the program. The LoadLibrary statement has an optional second parameter to allow you to specify an abbreviated reference name for the library's functions. The examples in this document use "Dev" for this reference name. Example:

Program's Startup code:

	Sub main()
	    LoadLibrary "DevInfoLib", "Dev"
	End Sub

Also, in order to use the DevInfoLib Library, the Dev.INF file must be present in your "nsbasic\lib" directory and the Dev.prc file must be added to your project as a resource.

All the parameter and return data types are either "Integer" or "String".

Function Index and Quick Reference:


Device Information
    CompanyID          ID = CompanyID()
    DeviceID           ID = DeviceID()
    HALid              ID = HALid()
    HwrMiscFlags       Flags = HwrMiscFlags()
    ProcessorID        ID = ProcessorID()
    GetSystemFeature   value = GetSystemFeature(ftr)
    GetFeature         value = GetFeature(creator, ftr)
    SetFeature         SetFeature creator, ftr, value
    GetBitValue        result = GetBitValue(intValue, bitNumber)
    SetBitValue        result = SetBitValue(intValue, bitNumber, bitValue)
    GetSerialNumber    SerialID = GetSerialNumber(AddCheckDigit)
    HotSyncUserName    HSUserName = HotSyncUserName()
    HotSyncUserID      HSUserID = HotSyncUserID()
    BatteryKind        Kind = BatteryKind()
    BatteryPct         Pct = BatteryPct()
    BatteryVolts       Volts = BatteryVolts()
    IsPluggedIn        State = IsPluggedIn()
    IsDocked           State = IsDocked()

DevInfoLib Function Reference:

Device Information

The device information functions provide information about the current device.

CompanyID

	ID = Dev.CompanyID()
Returns the company ID of the StyleTap runtime.
Returns:
	ID as String
Example:
	Dim ID as String

	ID = Dev.CompanyID()
If the code does not begin with a readable ASII character, an 8-byte string will be returned instead with the hexadecimal equivalent of the ID.

DeviceID

	ID = Dev.DeviceID()
Returns the device ID assigned by the device manufacturer. This is a 4-byte code, as opposed to the actual model name. Tables of common models can be found by searching the internet. One such list may be available at the following address: http://www.mobilegeographics.com/dev/devices.php
Returns:
	ID as String
Example:
	Dim ID as String

	ID = Dev.DeviceID()
If the code does not begin with a readable ASII character, an 8-byte string will be returned instead with the hexadecimal equivalent of the ID.

HALid

	ID = Dev.HALid()
Returns the "HAL" ID assigned by the device manufacturer. HAL stands for Hardware Abstraction Layer. It is returned as a 4-byte string value, when it contains a readable mneumonic value.
Returns:
	ID as String
Example:
	Dim ID as String

	ID = Dev.HALid()
If the code does not begin with a readable ASII character, an 8-byte string will be returned instead with the hexadecimal equivalent of the ID.

HwrMiscFlags

	Flags = Dev.HwrMiscFlags()
Returns an integer with hardware flags defined by the vendor. It may be useful to help distinguish between various models within some product lines. See aso DeviceID().
Returns:
	Flags as Integer
Example:
	Dim Flags as Integer

	Flags = Dev.HwrMiscFlags()
Unlike CompanyID() and DeviceID(), this is returned as an integer value instead of a string. This makes it useful to pass to BitValue() to check the status of individual bits.

ProcessorID

	ID = Dev.ProcessorID()
Returns an integer representing what type of processor is used in the device.
Returns:
	ID as Integer
	       Processor types include:
Example:
	Dim ID as Integer

	ID = Dev.ProcessorID()

GetSystemFeature

	value = Dev.GetSystemFeature(ftr)
Returns an integer with the contents of a specific system "feature" code.
Parameter:
	ftr as Integer
	       System feature number requested.
Returns:
	value as Integer
	       System feature value, or 0 if the feature does not exist.
Example:
	Dim value as Integer
	Dim ftr as Integer

	value = Dev.GetSystemFeature(ftr)
System feature numbers are documented in SystemMgr.h within the Palm OS SDK. The returned value may be passed to BitValue() to obtain the status of an individual bit.

GetFeature

	value = Dev.GetFeature(creator, ftr)
Returns an integer with the contents of any feature code set by any application. When used with creator ID "psys", it is the equivalent of calling GetSystemFeature() above.
Parameters:
	creator as String
	       Creator ID of the feature number requested.
	ftr as Integer
	       Feature number requested (0-32767)
Returns:
	value as Integer
	       Feature value, or 0 if the feature does not exist.
Example:
	Dim value as Integer
	Dim creator as String
	Dim ftr as Integer

	value = Dev.GetFeature(creator, ftr)
Feature values are used by some ROM based applications, and may be set by user applications as well. See SetFeature().

SetFeature

	Dev.SetFeature creator, ftr, value
Stores an integer value as a "feature" code. Features are a fast way to store integers which survive across invocations of a program. That is, they are like a global variable which can be recalled the next time the program is run. However, they do NOT survive a soft reset.
Parameters:
	creator as String
	       Creator ID associated with the feature.  It is recommended

	       to use your own application's creator ID for this.

	ftr as Integer
	       Feature number (0-32767)

	value as Integer
Example:
	Dim creator as String
	Dim ftr as Integer
	Dim value as Integer

	Dev.SetFeature creator, ftr, value
See also SetBitValue() to control individual bits of value.

GetBitValue

	result = Dev.GetBitValue(intValue, bitNumber)
Returns 1 if the specified bit number is 1, otherwise it returns 0.
Parameters:
	intValue as Integer
	       Bit to test; bits are numbered from right to left from 0 to 31.
	bitNumber as Integer
Returns:
	result as Integer
Example:
	Dim result as Integer
	Dim intValue as Integer
	Dim bitNumber as Integer

	result = Dev.GetBitValue(intValue, bitNumber)
BitValue() can be useful for analyzing values returned by such calls as HwrMiscFlags(), GetSystemFeature(), etc.

SetBitValue

	result = Dev.SetBitValue(intValue, bitNumber, bitValue)
Sets the bit specified by bitNumber to the specified bit value.
Parameters:
	intValue as Integer
	       Original integer value, before bit is changed.
	bitNumber as Integer
	       Bit to set; bits are numbered from right to left from 0 to 31.
	bitValue as Integer
	       New bit value (0 = off, 1 = on)
Returns:
	result as Integer
	       New integer value after changing the requested bit.
Example:
	Dim result as Integer
	Dim intValue as Integer
	Dim bitNumber as Integer
	Dim bitValue as Integer

	result = Dev.SetBitValue(intValue, bitNumber, bitValue)
This call may be useful with SetFeature().

GetSerialNumber

	SerialID = Dev.GetSerialNumber(AddCheckDigit)
Returns the device ROM serial number, if any, and optionally the check digit suffix. This value corresponds to the value display using the default app launcher Info menu on the Version tab, and appears just below the OS version. bit value.
Parameter:
	AddCheckDigit as Integer
	       Specify 0 to exclude the check digit; 1 to include the check digit.
Returns:
	SerialID as String
	       Serial number of device, when available.
Example:
	Dim SerialID as String
	Dim AddCheckDigit as Integer

	SerialID = Dev.GetSerialNumber(AddCheckDigit)
Many common devices do not have a ROM serial number, and no amount of wishing will make it so. Serial numbers will be a 12 byte string without the check digit, and a 14 byte string if the suffix is included (where byte 13 is a hyphen as shown by the app launcher Info menu item).

HotSyncUserName

	HSUserName = Dev.HotSyncUserName()
Returns the HotSync user name.
Returns:
	HSUserName as String
Example:
	Dim HSUserName as String

	HSUserName = Dev.HotSyncUserName()
If Hot Sync has never been run, or after a hard reset, this returns an empty string.

HotSyncUserID

	HSUserID = Dev.HotSyncUserID()
Returns the HotSync user ID number.
Returns:
	HSUserID as Integer
Example:
	Dim HSUserID as Integer

	HSUserID = Dev.HotSyncUserID()
The user ID number is a pseudo-random number assigned by Hot Sync to help warn against using two devices with the same user name on a given PC. Such can result in co-mingling or loss of data, so to help avoid it an ID number is assigned and compared with the desktop.

BatteryKind

	Kind = Dev.BatteryKind()
Returns the type of battery installed on the device.
Returns:
	Kind as Integer
	       One of the following values:
	         0 = Alkaline
	         1 = NiCad
	         2 = LiIon
	         3 = Rechargeable Alkaline
	         4 = NiMH
	         5 = LiIon, 1400mah
Example:
	Dim Kind as Integer

	Kind = Dev.BatteryKind()

BatteryPct

	Pct = Dev.BatteryPct()
Returns the approximate percentage of battery life remaining.
Returns:
	Pct as Integer
Example:
	Dim Pct as Integer

	Pct = Dev.BatteryPct()
This figure is an approximation. Warnings will be issued when the percentage drops to a certain level, and entirely force the unit off when critically low in order to attempt to preserve memory contents until the batteries are replaced.

BatteryVolts

	Volts = Dev.BatteryVolts()
Returns the current battery voltage multipled by 100. For example, 3.02 volts is returned as 302.
Returns:
	Volts as Integer
Example:
	Dim Volts as Integer

	Volts = Dev.BatteryVolts()

IsPluggedIn

	State = Dev.IsPluggedIn()
For rechargeable units, indicates if it is currently plugged in.
Returns:
	State as Integer
	       0 = not plugged in; 1 = plugged in
Example:
	Dim State as Integer

	State = Dev.IsPluggedIn()
The device may or may not also be in a cradle, or even if in a cradle it may not have power supplied. See also IsDocked().

IsDocked

	State = Dev.IsDocked()
Indicates if device is currently docked to a desktop.
Returns:
	State as Integer
	       0 = not docked; 1 = docked via cradle or cable
Example:
	Dim State as Integer

	State = Dev.IsDocked()
The device may or may not also be recharging. See also IsPluggedIn() above. Some units do not support detecting whether or not they are currently docked.