List Tag Types
In this example the program gets a list of supported tag types and the RFID identifies the tags that are within its range for supported tag types. The program does the following:
...
1. Gets the RFID parameters from the first driver and, using them, opens the connection to the RFID reader.
2. Identifies RFID tags by tag type and displays the list of tags, inside the reader's range, for each tag type.
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 ExampleListTagType {
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);
RfidTagType[] tagTypeList = rfidConnection.listTagTypes();
//----------------------(2)--------------------
for (int pos = 0; pos < tagTypeList.length; pos++) {
System.out.println(
"****** Identify Tags: " + tagTypeList[pos].getName());
RfidTag[] tags = rfidConnection.identify(tagTypeList[pos]);
if (tags.length > 0) {
for (int count = 0; count < tags.length; count++) {
System.out.print(
"Type : "
+ tagTypeList[pos].getName()
+ " ID: ");
byte[] tagID = tags[0].getTagID();
for (int i = 0; i < tagID.length; i++) {
System.out.print(tagID[i] + " ");
}
System.out.println();
}
System.out.println("Total: " + tags.length + "\n");
} else {
System.out.println(
"No tags in range for type "
+ tagTypeList[pos].getName());
}
}
} else {
System.out.println("There are no RFID drivers.");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
rfidConnection.close();
} catch (PIOSException pex) {
pex.printStackTrace();
}
}
}
}