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
 

25 JSR 257: Contactless Communication API

The Contactless Communication API (http://jcp.org/en/jsr/detail?id=257) is a Java ME optional package that allows applications to access information on contactless targets, such as Radio Frequency Identification (RFID) tags and bar codes. RFID tags are often used in business for item identification, article surveillance, and inventory. Each RFID tag contains a unique identification number used to identify a tagged object.

Using the JSR 257 API, an RFID reader can be built into an Oracle Java Wireless Client software phone stack, allowing the handset to read data from a tagged target and write data back to it. RFID readers use the 13.56 MHz radio frequency and the communication distance is usually less than 10 centimeters.

The Near Field Communication (NFC) Forum defines the NFC Data Exchange Format (NDEF) data packaging format. NDEF facilitates communication with an RFID tag, or between one NFC device and another. The Contactless Communication API provides a connection to any physical target that supports the NDEF standard, allowing applications to exchange data with any target tagged with NDEF formatting, regardless of actual physical type.

For an explanation of this implementation, see the Oracle Java Wireless Client Porting Guide.

25.1 Using ContactlessDemo

The Oracle Java ME SDK provides a way to test contactless communication. The MIDlet running on the emulator waits to detect an RFID tag. You can simulate the tag communication using the emulator's external events generator to detect and attach the tag. You can use one of the tags included in the sample, or create tag files of your own, as described in Section 25.2, "Tag File Formats."

  1. Launch the ContactlessDemo. The MIDlet registers the RFID tag listener, the NDEF tag listener and the NDEF record listener, then notifies you that it is waiting for a tag.

  2. In the emulator, choose Contactless Communication. In the external events generator the tag emulator supplies several tags by default: hello, nested, vcard, jdts, jdts2, and ndefEmpty.

  3. To test the connection, select an available tag and press the Attach tag button.

    In the emulator the MIDlet notifies you that the NDEF target is detected, displays the tag information, and prints the payload if it is a text record.

    In the external events generator, press the Detach tag button to end the session.

    Events are recorded in the log area. To clear the log, right-click and select delete text. To clear the emulator screen press the Clear soft button.

  4. To create your own tag, create a tag file according to the NDEF standard. For a sample, see Section 25.2, "Tag File Formats."

    In the external events generator, press the Create tag button, browse to select your tag file, and press Open. If the file is properly formed, the new tag is added to the available tags list.

    You can use the Remove tag button to remove any tag from the list. If it's a tag you created, the original file on disk is not affected. If the default tags are removed, they reappear when you restart the demo.

  5. Optional. Instead of performing interactive actions in the external events generator, you can use a script to do the same thing.

    Create a file as directed in Section 25.3, "Script Format." In the external events generator, click the Browse button to locate your script, then press Play.

25.2 Tag File Formats

Tags are created in XML format in accordance with the NFC and NDEF standards. To see how the sample files are formed, see: installdir\toolkit-lib\modules\emulator-ui-window-external-events\jsr257\conf\tags.

A sample file with several records might look like this:

<?xml version="1.0" encoding="UTF-8"?>
<jsr257client>
    <UID>12-CD-45-67-89-AB-CD</UID>

    <TargetProperties>
        <TargetProperty>NDEF</TargetProperty>
    </TargetProperties>

    <NDEFMessage>
        <NDEFRecord>
            <Format>MIME</Format>
            <Name>text/plain</Name>
            <Id>mimeid</Id>
            <Payload>Hello, MIME World!</Payload>
        </NDEFRecord>
        <NDEFRecord>
            <Format>MIME</Format>
            <Name>text/example</Name>
            <Id>urn:company:product:ndef:payload:2</Id>
            <Payload>payload2</Payload>
        </NDEFRecord>
        <NDEFRecord>
            <Format>EXTERNAL_RTD</Format>
            <Name>urn:nfc:ext:oracle.com:type1</Name>
            <Id></Id>
            <Payload>payload3</Payload>
        </NDEFRecord>
        <NDEFRecord>
            <Format>URI</Format>
            <Name>urn:company:product:test_uri</Name>
            <Id>urn:company:product:ndef:payload:4</Id>
            <Payload>payload4/<Payload>
        </NDEFRecord>
        <NDEFRecord>
            <Format>NFC_FORUM_RTD</Format>
            <Name>urn:nfc:wkt:Sp</Name>
            <Id></Id>
            <Payload>smart-poster</Payload>
        </NDEFRecord>
        <NDEFRecord>
            <Format>MIME</Format>
            <Name>text/x-vCard</Name>
            <Id>duke</Id>
            <Payload>BEGIN:VCARD VERSION:2.1 FN:Oracle TEL:+1-650-506-7000
                     ADR:500 Oracle Parkway City:Redwood Shores
                     State:CA;94065 END:VCARD
            </Payload>
        </NDEFRecord>
    </NDEFMessage>
</jsr257client>

25.3 Script Format

You can use the external events generator buttons to attach and detach a tag, or you can write a script to perform these actions. The script syntax is as follows:

# Comment:
  # this is a comment
# Tag definition:
    tag <tag name> <path to the tag xml file>
# Attach tag:
   attach <tag name>
# Delay. Ensures the tag is attached before other actions.
   wait <time in ms>
# Print tag information:
   print <tag name>
# Detach tag:
   detach <tag name>

This is a sample script:

   tag C D:\MyTags\ccomtag.xml
   attach C
   print C
   wait 10000
   detach C

In the external events generator click Browse and choose the script file, then press Play to run the script. The results are shown in the Log area. For example, if the sample script calls the sample tag file in Section 25.2, the log output is as follows:

[18:24:10]  Run Script: D:\JMESDKLocal\ccomtag.xml
[18:24:10]  Define tag 2058 (C)
[18:24:10]  Print 2058 (C)
[18:24:10]  Attached tag 2058 (C)
[18:24:10]  UID: 02-34-56-78-9A-BC-DE
Properties:  NDEF
NDEF message: 8 record(s)
#0: NDEF record:  format=MIME, name=text/plain, id.length=2, payload.length=18payload=Hello, MIME world!
#1: NDEF record:  format=MIME, name=text/example, id.length=34, payload.length=8payload=payload2
#2: NDEF record:  format=EXTERNAL_RTD, name=oracle.com:type1, payload.length=8payload=payload3
#3: NDEF record:  format=URI, name=urn:company:product:test_uri, id.length=34, payload.length=8
payload=payload4
#4: NDEF record:  format=EXTERNAL_RTD, name=company.com:type1, id.length=34, payload.length=8
payload=payload5
#5: NDEF record:  format=NFC_FORUM_RTD, name=Sp, payload.length=12
payload=smart-poster
#6: NDEF record:  format=URI, name=message/http, id.length=3, payload.length=56
payload=http://www.oracle.com/technetwork/java/javame/index.html
#7: NDEF record:  format=MIME, name=text/x-vCard, id.length=4, payload.length=122payload=BEGIN:VCARD VERSION:2.1 FN:Oracle TEL:+1-650-506-7000
ADR:500 Oracle Parkway; City:Redwood Shores;State:CA;94065 END:VCARD
[18:24:10]  Wait 10000ms
[18:24:20]  Detached tag 2058 (C)
[18:24:20]  Script finished.
[18:24:25]  Received data for unknown tag 2,058