Show TOC Start of Content Area

This graphic is explained in the accompanying textRead  Locate the document in its SAP Library structure

In this example the RFID reader reads data from a tag. The program does as described below:

...

       1.      Gets the RFID parameters from the first driver and, using them, opens the connection to the RFID reader.

       2.      Checks if the "identify all" and the "read single" attributes are supported by the driver.

       3.       Checks if there are RFID tags within range and for the first of those tags that has readable areas.

       4.      Reads the tag readable areas and displays the read data.

 

import com.sap.ip.me.api.pios.PIOSException;

import com.sap.ip.me.api.pios.connection.*;

import com.sap.ip.me.api.pios.rfid.*;

 

public class ExampleReadTag {

 

   public static void main(String[] args) {

 

       RfidConnection rfidConnection = null;

 

      try {

 

          //----------------------(1)--------------------

          Connector connector = Connector.getInstance();

 

          DriverInfo[] rfidDrivers =

              connector.listDrivers(ConnectionType.RFID);

 

          if (rfidDrivers.length > 0) {

 

              RfidParameters rfidParams = new RfidParameters(rfidDrivers[0]);

 

              rfidConnection = (RfidConnection) connector.open(rfidParams);

 

              //----------------------(2)--------------------

              if (rfidDrivers[0]

                 .isAttributeSupported(

                     RfidConnection.Attributes.IDENTIFY_ALL)

                 && rfidDrivers[0].isAttributeSupported(

                     RfidConnection.Attributes.READ_SINGLE)) {

 

                 //----------------------(3)--------------------

                 RfidTag[] tagList = rfidConnection.identify();

 

                 if (tagList.length > 0) {

 

                     boolean readableAreas = false;

 

                     RfidTag sampleTag = null;

 

                     for (int i = 0;

                        (i < tagList.length) && !readableAreas;

                        i++) {

 

                        RfidTagUserArea[] areas =

                           tagList[i].getTagType().getUserReadableAreas();

 

                        if (areas.length > 0) {

 

                           readableAreas = true;

 

                           sampleTag = tagList[i];

                        }

                     }

 

                     //----------------------(4)--------------------

                     if (sampleTag != null) {

 

                        RfidTagUserArea[] areas =

                           sampleTag.getTagType().getUserReadableAreas();

 

                        for (int j = 0; j < areas.length; j++) {

 

                           int readableAreaLength =

                               areas[j].getEndPos()

                                  - areas[j].getStartPos() + 1;

 

                           RfidTagData data =

                               rfidConnection.read(

                                  sampleTag,

                                  areas[j].getStartPos(),

                                  readableAreaLength);

 

                           if (data != null) {

                              

                               System.out.println(

                                  "Tag data for area #" + (j + 1) + " is: ");

 

                               for (int k = 0;

                                  k < data.getTagData().length;

                                  k++) {

 

                                  System.out.print(

                                      " " + data.getTagData()[k]);

 

                                  if (((k % 20) == 0) && (k > 0)) {

 

                                      System.out.println();

 

                                  }

                               }

                           }

                        }

                     } else {

 

                        System.out.println("No readable tags in range.");

 

                     }

                 } else {

 

                     System.out.println("No tags in range.");

 

                 }

              } else {

 

                 System.out.println(

                     "The required attributes are not supported by this driver.");

 

              }

          } else {

 

              System.out.println("There are no RFID drivers.");

 

          }

       } catch (Exception ex) {

 

          ex.printStackTrace();

 

       } finally {

 

          try {

 

              rfidConnection.close();

 

          } catch (PIOSException pex) {

 

              pex.printStackTrace();

 

          }

       }

   }

}

 

 

End of Content Area