Sirit Example Client RAPID

From RifidiWiki

Revision as of 23:13, 23 November 2010 by Amesycyxa (Talk | contribs)

Jump to: navigation, search

Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly

This class shows how to create a program to talk to the Sirit INfinity 510 reader with the use of Sirit's RAPID API.

<pre> /*

*  SiritClientRAPID.java
*
*  Created:	07.05.2009
*  Project:	RiFidi SiritClient
*  				http://www.rifidi.org
*  				http://rifidi.sourceforge.net
*  Copyright:	Pramari LLC and the Rifidi Project
*  License:	Lesser GNU Public License (LGPL)
*  				http://www.opensource.org/licenses/lgpl-license.html
*  Author:	Stefan Fahrnbauer - stefan@pramari.com
*/

package sandbox;

/**

* This class shows how to create a program to talk to the Sirit INfinity 510 reader
* with the use of Sirit's RAPID API.
*
* @author Stefan Fahrnbauer - stefan@pramari.com
*
*/

import com.sirit.data.DataManager; import com.sirit.driver.IEventListener; import com.sirit.mapping.EventInfo; import com.sirit.mapping.InfoManager; import com.sirit.mapping.ReaderManager; import com.sirit.mapping.SetupManager; import com.sirit.mapping.TagManager; import com.sirit.mapping.TagResponse; import com.sirit.mapping.TagResponseList;

import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket;


public class SiritClientRAPID implements IEventListener {

/* * IP Address of the reader */ private String ipAddress = "192.168.11.130";

/** * Constructor */ public SiritClientRAPID() { }

/** * Constructor - with IP Address * * @param ipAddr * IP Address for the reader */ public SiritClientRAPID(String ipAddress) { super(); this.ipAddress = ipAddress; }

/** * Executes the application */ public void run() { try { long startTime = System.currentTimeMillis();

// Open a connection to the reader DataManager dataManager = new DataManager( DataManager.ConnectionTypes.SOCKET, ipAddress, 0); dataManager.open(); System.out.println("Connection Opened");

// Get the reader's name InfoManager infoManager = new InfoManager(dataManager); String v = infoManager.getName(); System.out.println("Name: " + v); infoManager = null;

// Login as administrator ReaderManager readerManager = new ReaderManager(dataManager); if (!readerManager.login("admin", "readeradmin")) throw new Exception("Login attempt failed: " + readerManager.getLastErrorMessage()); v = readerManager.whoAmI(); System.out.println("Login: " + v);

// Open an event channel and get it's ID String id = dataManager.getEventChannel(this); System.out.println("Event Channel ID: " + id);

// Register for event.tag.report if (!readerManager.eventsRegister(id, "event.tag.report")) throw new Exception("Failure to register for event: " + readerManager.getLastErrorMessage()); System.out.println("Registered for event.tag.report");

// Set operating mode to active SetupManager setupManager = new SetupManager(dataManager); setupManager .setOperatingMode(SetupManager.OPERATING_MODE_TYPES.ACTIVE); System.out.println("Operating Mode: Active for 5 seconds");

// Sleep while handling tag events Thread.sleep(5000);

// Unregister for event.tag.report if (!readerManager.eventsUnregister(id, "event.tag.report")) throw new Exception("Failure to unregister for event: " + readerManager.getLastErrorMessage()); System.out.println("Unregistered for event.tag.report");

// Set operating mode to standby setupManager .setOperatingMode(SetupManager.OPERATING_MODE_TYPES.STANDBY); System.out.println("Operating Mode: Standby");

// List the TagDB System.out.println("Detected Tags:"); TagManager tagManager = new TagManager(dataManager); TagResponseList tagList = tagManager.dbGet("", "");

TagResponse tagResponse; for (int tagResponseID = 0; tagResponseID < tagList.getCount(); tagResponseID++) { tagResponse = tagList.getTagResponse(tagResponseID); System.out.println("TagID: " + tagResponse.getTagId()); System.out.println("\tAntenna: " + tagResponse.getAntenna()); System.out.println("\tCount: " + tagResponse.getRepeat()); System.out.println("\t1st Time: " + tagResponse.getFirst()); System.out.println("\tLast Time: " + tagResponse.getLast());

}

// Close the connection setupManager = null; readerManager = null; dataManager.close(); System.out.println("Connection Closed");

// Output the time to execute application long endTime = System.currentTimeMillis(); long t = endTime - startTime - 500; System.out.println("Estimated Time: " + t + "(ms)"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }


/** * Main method for this demo application * * @param args * Command line arguments first argument -IP Address of the * reader (optional) */ public static void main(String[] args) { // Create SiritClient object SiritClientRAPID scApp; if (args.length > 0) scApp = new SiritClientRAPID(args[0]); else scApp = new SiritClientRAPID();

// Execute the application scApp.run(); System.out.println("Exiting"); System.exit(0);

}

/** * Event Handler */ public void EventFound(Object sender, EventInfo eventInfo) { String tagID = eventInfo .getParameter(EventInfo.EVENT_TAG_ARRIVE_PARAMS.TAG_ID); System.out.println("Tag ID: " + tagID); }

} </pre>