Tuesday, December 7, 2010

Getting Reader Configuration with Java

The Java LTK is a great open source library that works well with Impinj RFID readers. However, some of the error messages it produces can be misleading. I recently had a customer who ran into an issue with the GET_READER_CONFIG message. The LLRP specification requires that you set the GPI, GPO and Antenna parameters when you request the entire reader configuration. If you don't, the error message you get from the Java LTK is "InvalidLLRPMessageException", which is true, but doesn't really point you in the right direction. Below is some sample code that shows how to request the entire configuration. Specifying zero for the Antenna ID and GPI/GPO Port returns the configuration for all antennas and ports.

public void getReaderConfig()
{
GET_READER_CONFIG_RESPONSE response;
try 
{
GET_READER_CONFIG readerConfig = new GET_READER_CONFIG();

// Request all config parameters.
readerConfig.setRequestedData
(new GetReaderConfigRequestedData
(GetReaderConfigRequestedData.All));
// Request configuration for all antennas and ports.
readerConfig.setAntennaID(new UnsignedShort(0));
readerConfig.setGPIPortNum(new UnsignedShort(0));
readerConfig.setGPOPortNum(new UnsignedShort(0));

// Send the message.
response = (GET_READER_CONFIG_RESPONSE) 
reader.transact(readerConfig, TIMEOUT_MS);

// Check if the we successfully 
// received the reader configuration.
StatusCode status = response.getLLRPStatus().getStatusCode();
if (status.equals(new StatusCode("M_Success")))
{
// Print out the reader config.
System.out.println(response.toXMLString());
}
else 
{
System.out.println("Error getting reader config.");
System.exit(1);
}
} 
catch (Exception e) 
{
System.out.println("Error getting reader config.");
e.printStackTrace();
}
}