Overview
This guide provides steps to perform various connection related task using RFID API3
Connect to an RFID Reader
Connection is the first step to talk to an RFID reader
- Import the package
- Create instance of Readers class with passing activity context as first parameter and enum value SERVICE_SERIAL as second parameter
- The Readers class instance gives a list of all available/paired RFID readers with an Android device. Readers list is in the form of ReaderDevice class.
- ReaderDevice class includes instance of RFIDReader class; which is root class to interface and performing all operations with RFID reader.
import com.zebra.rfid.api3.*;
readers = new Readers(this, ENUM_TRANSPORT.SERVICE_SERIAL);
ArrayList readersListArray = readers.GetAvailableRFIDReaderList();
ReaderDevice readerDevice = availableRFIDReaderList.get(0);
// Establish connection to the RFID Reader
rfidReader.connect();
Special Connection Handling Cases
In a normal scenario, the reader connects fine, but the following are the cases which require special handling at the time of connection. The following example demonstrates the connection is handled under try-catch block and OperationFailure exception is thrown by connection API is stored and used for further analysis
private OperationFailureException ex;
try {
// Establish connection to the RFID Reader
rfidReader.connect();
}
catch (InvalidUsageException e)
{
e.printStackTrace();
}
catch (OperationFailureException e)
{
e.printStackTrace();
ex = e;
}
Disconnect
When the application is done with the connection and operations on the RFID reader, it calls the following API to close the connection, and to release and clean up the resources.
// Disconnects reader and performs clean-up
rfidReader.disconnect();
NOTE: If a reader disconnection occurs, the reader.isConnected() flag may return the value false. If application has called thereader.connect()
then application should callreader.disconnect()
regardless of the flag status
Dispose
When the application main activity is destroyed, it is required to dispose the SDK instance so that it can cleanly exit (unregistration and unbind by SDK as required).
readers.Dispose();