Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.2 for Eclipse on Windows
E37550-02
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

5 Working With Devices

The Oracle Java ME SDK emulator simulates a CLDC device on your desktop computer. The emulator does not represent a specific device, but it provides correct implementations of its supported APIs.

The Oracle Java ME SDK provides default device skins. A skin is a thin layer on top of the emulator implementation that defines the appearance, screen characteristics, and input controls.

5.1 Emulating Devices

The SDK runs applications on an emulated device or a real device. Before you can run an application from the SDK, the Device Manager, which manages both emulated and real devices, must be running. When the Oracle Java ME SDK runs, the Device Manager automatically launches and starts detecting devices. The default devices shipped with the SDK are automatically found and displayed in the Device Selector window.

5.1.1 The Device Manager on Windows

The SDK uses the device manager to detect devices and displays the available devices in the Device Selector window. The Device Manager is a service and you can see it running in your Windows system tray. In the task manager, the process is labeled device-manager.exe.

device manager icon resides in Windows system tray

You can right-click on the icon and select Exit to stop the service.

Description of devmgrmenudef.gif follows
Description of the illustration devmgrmenudef.gif

To restart the device manager, double-click installdir\bin\device-manager.exe. You can also start it from the command line as described in Section 11.1, "Run the Device Manager."

Choosing Manage Device Addresses opens the Device Address Manager. Enter an IP address and select Add to add a device. Select an address and click Remove if you have an address you no longer want to detect. The device will no longer be displayed in the Device Selector.

5.1.2 Starting an Emulator

Typically an emulator is launched when a Java ME SDK project is run from the IDE or the command line.

You can open an emulator without running an application from the IDE. From the Windows Start menu, select Programs > Java(TM) ME Platform SDK 3.2 and choose the desired emulator. You can also click the emulator shortcuts installed on your Windows desktop.

Description of emu-start.gif follows
Description of the illustration emu-start.gif

To run an application from the emulator, select Application > Run MIDlet Suite (or IMlet Suite). Provide the path to the application and any other information, and click OK.

5.1.3 CLDC Application Management Software Home

The CLDC AMS home screen features three utilities:

  • Install Application. This utility opens a form in which you can specify a URL (or a file path) for a JAD file to install.

  • Manage Certificate Authorities. This feature displays the certificates authorities for the device. In this interface the white box indicates the certificate is checked (active). You can uncheck certificates that are not needed.

  • Output Console. The output console displays system output statements from a running application. The application must write to the Java standard output console using, for example: System.out.println("text");

    Start the Output Console, then start your application. Use F7, Switch running MIDlet, to switch between the application and the Output Console.

    The Output Console is an application that consumes resources. See Section 5.5, "Changing the Maximum Number of Concurrent Applications."

    Description of emu-output-console.gif follows
    Description of the illustration emu-output-console.gif

See Section 5.9, "Emulator Features" and Section 5.10, "Emulator Menus".

5.2 Adding a Real Device

The device selector can detect a device that has a compatible runtime. Typically this device has network capabilities and is connected to the computer running Java ME SDK.

  1. To detect a physical device, click CTRL-A, or click the device icon at the top of the Device Selector window.

  2. Type an IP address and click Next. Click Finish.

    You can also enter an IP address in the Device Manager, as described in Section 5.1.1, "The Device Manager on Windows".

  3. The physical device is listed in the appropriate platform tree. By default the device has "ExternalPhone" appended to the name.

    For example, if an IMP-NG device is detected it is placed in the IMP-NG node and given the name IMPNGExternalPhone1.

    For an example of how to configure and work with a real device, see the Oracle® Java ME Embedded Getting Started Guide for the Reference Board Platform. This document is available on the Java ME documentation site: http://docs.oracle.com/javame/index.html.

5.3 Viewing Device Properties

The Device Selector window lists all available devices grouped by platform. If this window is not visible, select Window > Show View > Other > Java ME SDK Tools > Device Selector.

If no Java ME platform is registered in Eclipse, the Device Selector is empty. If you see this message at startup, it typically means device discovery is incomplete and you must wait a few seconds.

Each sub node represents a device skin. Two instances are provided for some CLDC devices, for example, JavaMEPhone1 and JavaMEPhone2. Instances of the same device have the same capabilities but unique names and phone numbers, making it easy for you to test communication between devices of the same type.

For Device names, see Section 6.4, "Oracle Java ME SDK Directories." The properties for each device skin are stored in XML files in your user work directory. See Table 6-1.

See also: Section 5.3.1, "Platform Properties," Section 5.3.2, "Device Information," and Section 5.3.3, "Device Properties."

5.3.1 Platform Properties

To view properties for Oracle Java ME SDK from the device selector, click on the top-level node. The Properties window is, by default, docked in the upper right portion of the user interface.

5.3.2 Device Information

In the Device Selector window, double-click a device node. The Device Information tab opens in the central Main window. It displays a picture of the device and displays details, supported hardware capabilities, keyboard support, supported media formats, and the supported runtimes.

5.3.3 Device Properties

In the Device Selector window, click a device node (such as JavaMEPhone1) to display the device properties. The Properties window is, by default, docked in the upper right portion of the user interface.

5.4 Setting Device Properties

In the Device Selector Window, click on a device and see the information in the Properties pane. Any properties shown in gray font cannot be changed. You can adjust the device properties shown in black. Only CLDC options can be adjusted.

5.4.1 General

This section lists general properties that can be changed.

Phone Number 1. You can set the phone number to any appropriate sequence, considering country codes, area codes, and so forth. If you reset this value, the setting applies to future instances. The number is a base value for the selected device.

Heapsize. The heap is the memory allocated on a device to store your application's objects. The Heapsize property is the maximum heap size for the emulator. You can choose a new maximum size from the drop-down menu.

Security Domain. Select a security setting from the drop-down menu.

JAM storage size in KB. The amount of space available for applications installed over the air.

Locale. Type in the locale as defined in the MIDP 2.0 specification: http://jcp.org/en/jsr/detail?id=118

Remove MIDlet Suite in execution mode. If this option is enabled, record stores and other resources created by the MIDlet are removed when you exit the MIDlet (assuming the MIDlet was started in execution mode).

5.4.2 Monitor

If enabled (checked), the Check boxes for Trace GC (garbage collection), Trace Class Loading, Trace Exceptions, and Trace Method Calls activate tracing for the device the next time the emulator is launched. The trace output is displayed at runtime in the user interface Output window. Trace Method Calls returns many messages, and emulator performance can be affected.

5.4.4 Location Provider #1 and #2

These properties determine the selection of a location provider. Two providers are offered so that your application can test matching the location provider criteria.

If you select a property a short explanation is shown in the description area just below the Properties table. For more information on these values, see the Location API at http://jcp.org/en/jsr/detail?id=179.

5.4.5 Bluetooth and OBEX

Bluetooth. See Section 15.1, "Setting OBEX and Bluetooth Properties."

5.5 Changing the Maximum Number of Concurrent Applications

By default the CLDC runtime allows a maximum of five applications to run simultaneously. If you exceed the limit, you see the message, "No more concurrent applications allowed."

This number includes active applications, the Application Management Software (AMS), and any active on-device tooling agent (such as the profiler). You can close some applications, or increase the limit as follows:

  1. In the Oracle Java ME SDK installation, locate the following file:

    installdir\runtimes\cldc-hi\bin\jwc_properties.ini

  2. Locate the property MAX_ISOLATES. The value can be increased up to 15. However, you should be conservative as many applications running concurrently can affect performance.

5.6 Opening a Serial Port

In application code, you can use Connector.open("comm:COM1") to open a port on the device. On Windows, you can open a serial port such as COM1 or COM2.

5.7 Running a Project from the Device Selector

The SDK determines which open projects are suitable for a device. Right-click on the device and select a project from the context menu.

You can also launch the emulator to run a project from the command line, as explained in Section 11.3, "Emulator Command Line Options."

5.8 Running Projects Simultaneously on a Single Device

CLDC-based devices are capable of running multiple virtual machines. You can test this behavior in the emulator. Be sure the output window console is visible in the SDK. To test this feature, follow these steps:

  1. Open the sample projects Games and AudioDemo.

  2. In the device selector, choose a CLDC device and run Games. When the emulator launches run AudioDemo on the same device.

    As each MIDlet loads, the AMS automatically installs it.

  3. In AudioDemo, launch the Audio Player, and play the JavaOne theme.

    Select AudioPlayer, then from the soft menu, select 1, Launch. Select JavaOne Theme and press the Play soft button.

  4. In the emulator, choose Application > AMS Home, or press F4.

    Select Games. From the soft menu, select 1, Open. The music continues to play while you are able to simultaneously launch and play games.

  5. Select Application > AMS Home, or press F4. Highlight AudioSamples, and from the soft menu, select 6, Bring to foreground. Press the Pause soft key. The music stops playing.

  6. Select Application > AMS Home, or press F4. Highlight AudioSamples and from the soft menu, select 5, Open. Select Bouncing Ball from the list and press the Launch soft button. Select MIDI background and press the Play soft button.

  7. Select Application > AMS Home, or press F4. Select Application > Switch Running MIDlet. Select Audio Player and press the Switch to soft button. You can press the Play soft button to resume the Audio Player.

5.9 Emulator Features

Figure 5-1, "Emulator Features" shows common emulator features available on emulators for the CLDC platform.

Device Name. Shown in the upper window frame. See Section 6.4, "Device Names."

Transmission Indicator. On the upper left of the emulator image, this blue light turns on when a transmission is occurring. Typically you see it when an application is installed over-the-air, or when a message is being sent or received. For example, when you receive a message from the WMA console.

Menus. See Section 5.10, "Emulator Menus."

Device ID. See Table 6-1, "Device Names".

Exit Button. Pushing the button on the upper right of the emulator image has the same effect as selecting Application > Exit.

Emulator Status Bar. Information about the current system state is shown in the status bar at the bottom of the emulator window.

Figure 5-1 Emulator Features

Description of Figure 5-1 follows
Description of "Figure 5-1 Emulator Features"

5.10 Emulator Menus

The emulator for the CLDC platform has Application, Device, Edit, View, and Help menus.

5.10.1 Application

The Application menu is fully populated for the CLDC platform. The Application options are as follows:

Option Accelerator Description

Run MIDlet suite


Emulator interface for launching MIDlets.

AMS Home

F4

Exit the current application and return to the Application Management Software home.

Stop

F10

Stops the currently running MIDlet.

Change Locale


This option only works with localized MIDlets.

Enter a locale identifier. The format is similar to Java SE 6, as follows:

2-letter-lang-code separator 2-letter-country-code

For example, en-US, cs-CZ, zh-CN, ja-JP. The separator can be a dash or an underscore.

Resume

F6

Resume a suspended application.

Suspend

F5

Pause a running application.

Do not use this option if you are running the memory monitor.

Switch Running MIDlet

F7

When you have multiple MIDlets running, toggle between them. You see a list of running MIDlets and you can chose the one you want to switch to. See Section 5.8, "Running Projects Simultaneously on a Single Device."

Exit

Exit button on emulator upper right

Close the emulator process and stop the build process (or processes).


5.10.2 Device

This menu is available on CLDC platforms only.

5.10.2.1 Messages

Choose Device > Messages to see what is written in the message area. This is the emulator's Inbox. The Inbox displays WMA messages that are addressed to the device, not an application on the device. Messages are sent to this interface in the following cases:

  • an MMS message is sent without an AppID in the address

  • an SMS message is sent without a port in the address (or the port number is 0)

  • an SMS text message is sent with a port in the address, but there is not a Java ME application listening on the specified port

To test sending messages to the inbox use the WMA Console in Eclipse, or from the command line, use wma-tool.exe to send SMS messages. Note, wma-tool.exe requires an AppID for MMS, so wma-tool can not be used to send an MMS.

5.10.2.2 Landmark Stores

Choose Device > Landmark Stores to open the Landmark Store utility. In this interface you can view and edit a landmark store installed as part of an application. You can also create a new landmark store, define landmarks, define landmark categories, and assign landmarks to categories.

5.10.2.3 Orientation

This option is only visible for the CLDC emulator.

Use this feature to test your application's ability to display in portrait and landscape formats. The default is 0 degrees. Change the orientation to 90, 180, or 270 degrees. You can also rotate 90 degrees clockwise (F8) or counterclockwise (F9) from the current position.

5.10.2.4 External Events Generator

The External Events Generator provides a way to interact with an application by injecting events. The interaction may be through a user interface, or through a script file. The following menu options each have a tab on the External Events Generator. The use of the External Events Generator is addressed in the discussion for each JSR.

  • Contactless Communication. This option is only visible for the CLDC emulator. See Section 25.1, "Using ContactlessDemo."

  • File Connection. Section 14.1, "FileConnection API."

  • GPIO. This General Purpose Input Output (GPIO) option is only visible for the IMP-NG emulator.

    By default this tab displays ports and pins for a specific device described in Section 3.7.1, "GPIODemo." You can create a custom skin to represent a different device. Section 5.11.3.1, "General Purpose Input Output (GPIO)."

    See the Device Access API (installdir\docs\api\deviceaccess) for a description of the GPIO interface.

  • Location. Section 18.1, "Setting the Emulator's Location at Runtime."

  • MMIO. The memory-mapped I/O (MMIO) option is only visible for the IMP-NG emulator. From the Device dropdown list, choose one of the default devices:

    • TEST_DEVICE. A little Endian device that contains all block types: byte, short, int, long, and block. Writes to this device also affect BIG_ENDIAN_DEVICE which shares the address space.

    • BIG_ENDIAN_DEVICE. A Big Endian device that shares the address space with the TEST_DEVICE, therefore it contains the same memory blocks. Writes to this device also affect TEST_DEVICE which shares the address space.

    • WDOGLOG. A Little Endian device that supports only the block type.

    • RTC. STM32F2xx RTC device. A Little Endian device that supports only the int type.

    If you are using a custom skin created with the Skin Creator (see Section 5.11, "Using the Custom Device Skin Creator") the device list might include additional devices.

    See the Device Access API (installdir\docs\api\deviceaccess)and the Embedded Support API (installdir\docs\api\embedded-support-api) for descriptions of the MMIO interface.

  • Sensors. This option is only visible for the CLDC emulator. See Section 24.2, "Using a Mobile Sensor Project" and Section 24.3, "Creating a Sensor Script File."

  • SPI. In the default SPI implementation buffered written data can be read from the Slave named SPI. If you have created a custom implementation with the Skin Creator, the Slave dropdown list might have additional slaves

5.10.3 Edit

The Edit menu provides basic editing utilities for the CLDC platform.

Option Accelerator Description

Copy

CTRL-C

Copy selected material to the paste buffer.

Cut

CTRL-X

Move selected material to the paste buffer.

Paste

CTRL-V

Insert the contents of the paste buffer.


5.10.4 View

The only View option available is Always On Top.

Option Description

Always On Top

Keeps the emulator in the foreground. This is especially useful when you are running multiple emulator instances and you want to see them all and send messages between devices.


5.10.5 Help

The Help menu displays an abbreviated helpset specifically for the emulator window.

5.11 Using the Custom Device Skin Creator

With the Custom Device Skin Creator you can create your own skins. The appearance of the custom skins is generic, but the functionality can be tailored to your own specifications.

5.11.1 Creating a New Custom Device Skin

Follow these steps to create a new custom device skin.

  1. Launch the skin creator from the your installation's bin directory. For example:

    C:\Java_ME_platform_SDK_3.2\bin\skin-creator.exe

    The custom device tree displays Java ME platforms and custom devices, if any.

  2. Select a platform and click the New... button.

  3. Specify a Name and Description.

  4. Change the default configuration to match your specifications. If you are creating an IMP-NG skin, see Section 5.11.3, "IMP-NG Skin Options" for description of the IMP-NG tabs.

  5. Click OK. Your skin is added to the custom device tree.

    Your custom skin definition is saved in installdir\toolkit-lib\devices. It can be used to run projects from the IDE or from the command line.

    The custom device tree affects what appears in the Device Selector. For example, if you don't want a custom skin to appear in the device selector, you must remove it from the Skin Creator's custom device tree.

  6. To detect the device, select Window > Preferences >Java ME > Device Management.

    Click Manual Install. The Manual Device Installation window opens.

    In the "Specify search directory" field, browse to the your Java ME SDK installation directory. For example: C:\Java_ME_platform_SDK_3.2. When the devices are detected, click Finish to close the window, then click OK.

  7. The detected device(s) appear in the Device Selector.

5.11.2 Managing Custom Skins

Custom skins should always be managed using the Custom Device Skin Creator. Using the tool ensures that your skin will be properly detected and integrated with the Oracle Java ME SDK.

  • Edit. Select a device to change, and click Edit.

  • Clone. Select a device to copy, and click Clone. To prevent confusion, be sure to provide a unique name.

  • Export. Select a device to save, and click Export.

    When a custom device is created it is saved in installdir\toolkit-lib\devices, therefore you could lose your device if you reinstall.

    An exported device is stored in a .zip file and saved in the user's My Documents directory (typically userhome\My Documents).

  • Import. Select a node in the custom device tree and click Import. Choose a .zip file created with the Export command.

  • Remove. Select a device to delete and click Remove. This action removes the skin from the device selector and deletes it from its default location on disk (if you have exported the skin to a different location you can, import it at a later time).

5.11.3 IMP-NG Skin Options

When you create a new IMP-NG skin you can use the default implementation or create your own custom implementation for the interfaces discussed in this section.

See the following resources for in-depth descriptions of the IMP-NG interfaces or devices:

  • Device Access API (installdir\docs\api\deviceaccess)

  • Embedded Support API (installdir\docs\api\embedded-support-api)

  • For more information about default devices look at an IMP-NG property file:

    userhome\javame-sdk\version\work\IMPNGDevice1\device.properties

5.11.3.1 General Purpose Input Output (GPIO)

A GPIO port is a platform-defined grouping of GPIO pins that may be configured for output or input. Output ports are both writable and readable while input ports are only readable. Note that GPIO pins that are part of a GPIO port cannot be retrieved nor controlled individually as GPIOPin instances.

Click Add Port to add entries to the Ports table. Each item in a Ports table row is editable. Check Output to set the port direction to output.

A GPIO pin may be configured for output or input. Output pins are both writable and readable while input pins are only readable. Note, an input listener can only be assigned to a pin set for input.

Click Add Pin to add a row to the Pins table. The ID and name are editable. Click Output to make a pin both readable and writable. Click in the Initial Value column to toggle the Initial Value from Off to On.

5.11.3.2 Inter-Integrated Circuit (I2C) and Serial Peripheral Interface (SPI)

The process for configuring I2C and SPI interfaces is very similar.

On an I2C bus, data is transferred between the I2C master device and an I2C slave device through single or combined messages. On an SPI bus, data is transferred between the SPI master device and an SPI slave device in full duplex. That is, data is transmitted by the SPI master to the SPI slave at the same time data is received from the SPI slave by the SPI master. See the Embedded Support API for more details.

  • Select Sample Echo to choose the default bus implementation. This default implementation simply reads buffered written data from the slave.

  • Choose Custom to specify your own bus implementation.

    1. Supply your bus implementation JAR file and the name of the Java class that implements the bus.

      For I2c the bus is:

      com.oracle.jme.toolkit.deviceaccess.i2c.I2CSlaveBus

      For SPI the bus is:

      com.oracle.jme.toolkit.deviceaccess.spi.SPISlaveBus

    2. To add Slaves, click Add and specify an ID and Name. For SPI specify the Word Length as well.

5.11.3.3 Memory-Mapped I/O (MMIO)

The default devices are described in Section 5.10.2.4, "External Events Generator."

If you want to provide your own MMIO emulation, you must specify a custom handler.

Supply your implementation JAR file and the name of the Java class that implements com.oracle.jme.toolkit.deviceaccess.mmio.MMIOHandler. For comparison, the default JAR file is:

installdir\toolkit-lib\devices\IMPNGDevice\code\emulator_deviceaccess_mmio-sample-handler.jar

To add devices to the custom MMIO implementation, use the Devices and Device Memory tables as follows:

  1. Click Add Device to add a row to the Devices table.

    • A default ID is assigned but you can double-click in the ID column to edit the value.

    • A default Name is supplied, but it can also be edited.

    • In the Byte Ordering column, make a selection from the dropdown list.

  2. Click a row in the Device table to select a Device.

  3. Click Add Memory.

    • In the Type column, make a selection from the dropdown list. Double-click to edit the Address column entries.

      If the type is Block you can double-click to edit the Size column entries as well as the Address column entries.

  4. Click OK.