com.sap.ip.me.api.pios.rfid
Class RfidConnection

java.lang.Object
  extended bycom.sap.ip.me.api.pios.connection.Connection
      extended bycom.sap.ip.me.api.pios.rfid.RfidConnection

public abstract class RfidConnection
extends Connection

RfidConnection defines a connection (session) with a specific RFID reader. RFID operations are executed and results are returned within the context of the connection. Includes methods to list all supported tag types, identify tags in range and read/write operation on tags.

Example: Identify all tags within the RFID reader area of coverage and write some bytes to the first writable area of the first identified tag.
 
 
 	Connector connector = Connector.getInstance();
 			
 	DriverInfo[] rfidDrivers = connector.listDrivers(ConnectionType.RFID);
 			
 	RfidParameters rfidParams = new RfidParameters(rfidDrivers[0]);
 			
 	RfidConnection rfidConnection = (RfidConnection)connector.open(rfidParams);
 
	RfidTag[] tagList = rfidConnection.identify();
 
	if(tagList.length > 0) { 
 
 		RfidTagUserArea[] tagArea = tagList[0].getTagType().getUserWritableAreas();
				
		if (tagArea.length > 0) {
			
			int writableSize = tagArea[0].getEndPos() - tagArea[0].getStartPos() + 1;

			byte[] dataBytes = new byte[writableSize];

			new Random().nextBytes(dataBytes);  //creates a byte array with random values
					
			rfidConnection.write(tagList[0], tagArea[0].getStartPos(), dataBytes); 
										
		}
		else {
		
			System.out.println("Tag is read only!");
					
		}
	} 
  else {
  
  	System.out.println("No tags in range.");
  
  }

  rfidConnection.close();

 
 
Example: Program and lock a new tag id.
 
 
 	Connector connector = Connector.getInstance();
 			
 	DriverInfo[] rfidDrivers = connector.listDrivers(ConnectionType.RFID);
 			
 	RfidParameters rfidParams = new RfidParameters(rfidDrivers[0]);
 			
 	RfidConnection rfidConnection = (RfidConnection)connector.open(rfidParams);
 
 	rfidConnection.programTagID(new byte[]{1,2,3,4,5});
 
 	rfidConnection.lockTagID("pwd".getBytes());
  
  rfidConnection.close();
 
 
 
Example: Reset the first tag identified.
 
 
 	Connector connector = Connector.getInstance();
 			
 	DriverInfo[] rfidDrivers = connector.listDrivers(ConnectionType.RFID);
 			
 	RfidParameters rfidParams = new RfidParameters(rfidDrivers[0]);
 			
 	RfidConnection rfidConnection = (RfidConnection)connector.open(rfidParams);
 
	RfidTag[] tagList = rfidConnection.identify();
 
	if(tagList.length > 0) { 
 
 		rfidConnection.resetTagID(tagList[0], "pwd".getBytes()); //Unlocks a tag id and reset it's contents to zero.
 
	}  
 
  rfidConnection.close();

 
 

To determine if a required RFID functionality is provided by a driver use a DriverInfo instance provided by the connector.

Example: Determine if the RFID driver supports the read method.
 
	   	
	Connector connector = Connector.getInstance();
 			
 	DriverInfo[] rfidDrivers = connector.listDrivers(ConnectionType.RFID);
	 	
	if (rfidDrivers[0].isAttributeSupported(RfidConnection.Attributes.READ_SINGLE)) {
		
		//Add some code here 
	}   
  else {
  
  	System.out.println("Read operation not supported by this driver.");
  } 

  rfidConnection.close();
  
 
 

Since:
MI 2.5
Author:
Abaco
See Also:
RfidParameters, Connection, RfidTag, RfidTagData, RfidTagType

Nested Class Summary
static interface RfidConnection.Attributes
          Contains all possible attribute names for RFID.
 
Field Summary
 
Fields inherited from class com.sap.ip.me.api.pios.connection.Connection
attributesFileName, cfgFile, opened, parameters
 
Constructor Summary
protected RfidConnection()
          Constructs a new RFID connection.
 
Method Summary
abstract  TagConfigurationManager getTagConfigurationManager()
          Returns the TagConfigurationManager object for this RFID connection.
abstract  RfidTagType getTagType(java.lang.String typeName)
          Returns an RfidTagType object containing the tag type information for the specified tag type configuration name.
abstract  RfidTag[] identify()
          Returns all the tags available within the RFID reader area of coverage.
abstract  RfidTag[] identify(RfidTagType tagType)
          Returns all the tags available within the RFID reader area of coverage that matches the tag type specified.
abstract  RfidTagType[] listTagTypes()
          Returns an RfidTagType array containing the tag types supported by the selected RFID reader.
abstract  void lockTagID(byte[] password)
          The lockTagID function locks a tag id so it cannot be changed.
abstract  void programTagID(byte[] newTagID)
          Programs a tag with a new TagID.
abstract  RfidTagData read(RfidTag tag, int startPos, int length)
          Reads bytes from the selected tag.
abstract  void resetTagID(RfidTag tag, byte[] password)
          Resets a tag id, making it programmable again.
abstract  void write(RfidTag tag, int startPos, byte[] data)
          Writes bytes to the selected tag.
 
Methods inherited from class com.sap.ip.me.api.pios.connection.Connection
close, getParameters, isOpen, open
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RfidConnection

protected RfidConnection()
                  throws PIOSException
Constructs a new RFID connection.

Throws:
PIOSException - thrown if an error is detected while creating or opening an RFID connection.
Method Detail

identify

public abstract RfidTag[] identify()
                            throws RfidException,
                                   UnsupportedException
Returns all the tags available within the RFID reader area of coverage. An empty array will be returned if there are no tags in range.

Returns:
An RfidTag object array.
Throws:
RfidException - thrown if an error occurs while communicating with the RFID engine.
UnsupportedException - thrown if the identify method is not supported by the RFID engine.

identify

public abstract RfidTag[] identify(RfidTagType tagType)
                            throws RfidException,
                                   UnsupportedException
Returns all the tags available within the RFID reader area of coverage that matches the tag type specified. An empty array will be returned if there are no tags in range.

Parameters:
tagType - the tag type object containing the tag type to identify
Returns:
An RfidTag object array.
Throws:
RfidException - thrown if an error occurs while communicating with the RFID engine.
UnsupportedException - thrown if the identify by tag type method is not supported by the RFID engine.

read

public abstract RfidTagData read(RfidTag tag,
                                 int startPos,
                                 int length)
                          throws RfidException,
                                 UnsupportedException
Reads bytes from the selected tag.

Parameters:
tag - the RfidTag object containing the tag to read
startPos - the starting byte position to perform the read operation
length - the amount of bytes to read
Returns:
An RfidTagData object read.
Throws:
RfidException - thrown if an error occurs while communicating with the RFID engine or the specified tag could not be read.
UnsupportedException - thrown if the read method is not supported by the RFID engine.

write

public abstract void write(RfidTag tag,
                           int startPos,
                           byte[] data)
                    throws RfidException,
                           UnsupportedException
Writes bytes to the selected tag.

Parameters:
tag - the RfidTag object containing the tag to write
startPos - the starting byte position to perform the write operation
data - the byte representation of the data to write
Throws:
RfidException - thrown if an error occurs while communicating with the RFID engine or the specified tag could not be written.
UnsupportedException - thrown if the write method is not supported by the RFID engine.

programTagID

public abstract void programTagID(byte[] newTagID)
                           throws RfidException,
                                  UnsupportedException
Programs a tag with a new TagID. All tags within the RFID range will be updated with the new tag id. If no tag id duplicates are intended the user must make sure that only one tag is in the reader's area of coverage before performing this operation.

Parameters:
newTagID - the byte representation of the tag id to write
Throws:
RfidException - thrown if an error occurs while communicating with the RFID engine or the specified tag id could not be programmed.
UnsupportedException - thrown if the program tag id method is not supported by the RFID engine.

lockTagID

public abstract void lockTagID(byte[] password)
                        throws RfidException,
                               UnsupportedException
The lockTagID function locks a tag id so it cannot be changed. Once locked, tag must be reset in order to be reprogram with a new the tag id. All tags within the RFID range will be locked.

Parameters:
password - the password used to lock a tag. This password must be used when unlocking the tag. Password required length or contents may vary depending on the type of tag being used. The RfidTagType class can be used to obtain information about password requirements
Throws:
RfidException - thrown if an error occurs while communicating with the RFID engine or the specified tag id could not be locked.
UnsupportedException - thrown if the lock tag id method is not supported by the RFID engine.

resetTagID

public abstract void resetTagID(RfidTag tag,
                                byte[] password)
                         throws RfidException,
                                UnsupportedException
Resets a tag id, making it programmable again. This command should be used to reset a locked tag. This method unlocks and erases the tag id.

Parameters:
tag - the RfidTag object containing the tag to reset.
password - the password previously used to lock the tag. The password provided must match the password used to lock the tag.
Throws:
RfidException - thrown if an error occurs while communicating with the RFID engine or the specified tag id could not be unlocked or erased.
UnsupportedException - thrown if the reset tag id method is not supported by the RFID engine.

listTagTypes

public abstract RfidTagType[] listTagTypes()
                                    throws RfidException
Returns an RfidTagType array containing the tag types supported by the selected RFID reader. Returns an empty array if no tag types have been configured.

Returns:
An RfidTagType array containing the tag types supported by the selected RFID reader.
Throws:
RfidException - thrown if an error occurs while communicating with the RFID driver.

getTagType

public abstract RfidTagType getTagType(java.lang.String typeName)
                                throws RfidException
Returns an RfidTagType object containing the tag type information for the specified tag type configuration name.

Parameters:
typeName - tag type configuration name specified on the configuration file
Returns:
An RfidTagType object containing the tag type corresponding to the specified tag type configuration name.
Throws:
RfidException - thrown if an error occurs while communicating with the RFID driver or if the specified tag type was not configured.

getTagConfigurationManager

public abstract TagConfigurationManager getTagConfigurationManager()
                                                            throws ConfigurationException
Returns the TagConfigurationManager object for this RFID connection.

Returns:
A TagConfigurationManager object.
Throws:
ConfigurationException - thrown when unable to return the tag configuration manager for this connection.


Copyright © 2005 SAP AG. All Rights Reserved.