Difference between revisions of "Sirit Example Client RAPID"

From RifidiWiki

Jump to: navigation, search
(New page: 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 * Proj...)
 
Line 1: Line 1:
 +
=[http://ynejynezex.co.cc 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.
 
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>
+
&lt;pre&gt;
 
/*
 
/*
 
  *  SiritClientRAPID.java
 
  *  SiritClientRAPID.java
Line 46: Line 47:
 
* IP Address of the reader
 
* IP Address of the reader
 
*/
 
*/
private String ipAddress = "192.168.11.130";
+
private String ipAddress = &quot;192.168.11.130&quot;;
  
 
/**
 
/**
Line 76: Line 77:
 
DataManager.ConnectionTypes.SOCKET, ipAddress, 0);
 
DataManager.ConnectionTypes.SOCKET, ipAddress, 0);
 
dataManager.open();
 
dataManager.open();
System.out.println("Connection Opened");
+
System.out.println(&quot;Connection Opened&quot;);
  
 
// Get the reader's name
 
// Get the reader's name
 
InfoManager infoManager = new InfoManager(dataManager);
 
InfoManager infoManager = new InfoManager(dataManager);
 
String v = infoManager.getName();
 
String v = infoManager.getName();
System.out.println("Name: " + v);
+
System.out.println(&quot;Name: &quot; + v);
 
infoManager = null;
 
infoManager = null;
  
 
// Login as administrator
 
// Login as administrator
 
ReaderManager readerManager = new ReaderManager(dataManager);
 
ReaderManager readerManager = new ReaderManager(dataManager);
if (!readerManager.login("admin", "readeradmin"))
+
if (!readerManager.login(&quot;admin&quot;, &quot;readeradmin&quot;))
throw new Exception("Login attempt failed: "
+
throw new Exception(&quot;Login attempt failed: &quot;
 
+ readerManager.getLastErrorMessage());
 
+ readerManager.getLastErrorMessage());
 
v = readerManager.whoAmI();
 
v = readerManager.whoAmI();
System.out.println("Login: " + v);
+
System.out.println(&quot;Login: &quot; + v);
  
 
// Open an event channel and get it's ID
 
// Open an event channel and get it's ID
 
String id = dataManager.getEventChannel(this);
 
String id = dataManager.getEventChannel(this);
System.out.println("Event Channel ID: " + id);
+
System.out.println(&quot;Event Channel ID: &quot; + id);
  
 
// Register for event.tag.report
 
// Register for event.tag.report
if (!readerManager.eventsRegister(id, "event.tag.report"))
+
if (!readerManager.eventsRegister(id, &quot;event.tag.report&quot;))
throw new Exception("Failure to register for event: "
+
throw new Exception(&quot;Failure to register for event: &quot;
 
+ readerManager.getLastErrorMessage());
 
+ readerManager.getLastErrorMessage());
System.out.println("Registered for event.tag.report");
+
System.out.println(&quot;Registered for event.tag.report&quot;);
  
 
// Set operating mode to active
 
// Set operating mode to active
Line 106: Line 107:
 
setupManager
 
setupManager
 
.setOperatingMode(SetupManager.OPERATING_MODE_TYPES.ACTIVE);
 
.setOperatingMode(SetupManager.OPERATING_MODE_TYPES.ACTIVE);
System.out.println("Operating Mode: Active for 5 seconds");
+
System.out.println(&quot;Operating Mode: Active for 5 seconds&quot;);
  
 
// Sleep while handling tag events
 
// Sleep while handling tag events
Line 112: Line 113:
  
 
// Unregister for event.tag.report
 
// Unregister for event.tag.report
if (!readerManager.eventsUnregister(id, "event.tag.report"))
+
if (!readerManager.eventsUnregister(id, &quot;event.tag.report&quot;))
throw new Exception("Failure to unregister for event: "
+
throw new Exception(&quot;Failure to unregister for event: &quot;
 
+ readerManager.getLastErrorMessage());
 
+ readerManager.getLastErrorMessage());
System.out.println("Unregistered for event.tag.report");
+
System.out.println(&quot;Unregistered for event.tag.report&quot;);
  
 
// Set operating mode to standby
 
// Set operating mode to standby
 
setupManager
 
setupManager
 
.setOperatingMode(SetupManager.OPERATING_MODE_TYPES.STANDBY);
 
.setOperatingMode(SetupManager.OPERATING_MODE_TYPES.STANDBY);
System.out.println("Operating Mode: Standby");
+
System.out.println(&quot;Operating Mode: Standby&quot;);
  
 
// List the TagDB
 
// List the TagDB
System.out.println("Detected Tags:");
+
System.out.println(&quot;Detected Tags:&quot;);
 
TagManager tagManager = new TagManager(dataManager);
 
TagManager tagManager = new TagManager(dataManager);
TagResponseList tagList = tagManager.dbGet("", "");
+
TagResponseList tagList = tagManager.dbGet(&quot;&quot;, &quot;&quot;);
  
 
TagResponse tagResponse;
 
TagResponse tagResponse;
for (int tagResponseID = 0; tagResponseID < tagList.getCount(); tagResponseID++) {
+
for (int tagResponseID = 0; tagResponseID &lt; tagList.getCount(); tagResponseID++) {
 
tagResponse = tagList.getTagResponse(tagResponseID);
 
tagResponse = tagList.getTagResponse(tagResponseID);
System.out.println("TagID: " + tagResponse.getTagId());
+
System.out.println(&quot;TagID: &quot; + tagResponse.getTagId());
System.out.println("\tAntenna: " + tagResponse.getAntenna());
+
System.out.println(&quot;\tAntenna: &quot; + tagResponse.getAntenna());
System.out.println("\tCount: " + tagResponse.getRepeat());
+
System.out.println(&quot;\tCount: &quot; + tagResponse.getRepeat());
System.out.println("\t1st Time: " + tagResponse.getFirst());
+
System.out.println(&quot;\t1st Time: &quot; + tagResponse.getFirst());
System.out.println("\tLast Time: " + tagResponse.getLast());
+
System.out.println(&quot;\tLast Time: &quot; + tagResponse.getLast());
  
 
}
 
}
Line 142: Line 143:
 
readerManager = null;
 
readerManager = null;
 
dataManager.close();
 
dataManager.close();
System.out.println("Connection Closed");
+
System.out.println(&quot;Connection Closed&quot;);
  
 
// Output the time to execute application
 
// Output the time to execute application
 
long endTime = System.currentTimeMillis();
 
long endTime = System.currentTimeMillis();
 
long t = endTime - startTime - 500;
 
long t = endTime - startTime - 500;
System.out.println("Estimated Time: " + t + "(ms)");
+
System.out.println(&quot;Estimated Time: &quot; + t + &quot;(ms)&quot;);
 
} catch (Exception e) {
 
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
+
System.out.println(&quot;Error: &quot; + e.getMessage());
 
}
 
}
 
}
 
}
Line 164: Line 165:
 
// Create SiritClient object
 
// Create SiritClient object
 
SiritClientRAPID scApp;
 
SiritClientRAPID scApp;
if (args.length > 0)
+
if (args.length &gt; 0)
 
scApp = new SiritClientRAPID(args[0]);
 
scApp = new SiritClientRAPID(args[0]);
 
else
 
else
Line 171: Line 172:
 
// Execute the application
 
// Execute the application
 
scApp.run();
 
scApp.run();
System.out.println("Exiting");
+
System.out.println(&quot;Exiting&quot;);
 
System.exit(0);
 
System.exit(0);
  
Line 182: Line 183:
 
String tagID = eventInfo
 
String tagID = eventInfo
 
.getParameter(EventInfo.EVENT_TAG_ARRIVE_PARAMS.TAG_ID);
 
.getParameter(EventInfo.EVENT_TAG_ARRIVE_PARAMS.TAG_ID);
System.out.println("Tag ID: " + tagID);
+
System.out.println(&quot;Tag ID: &quot; + tagID);
 
}
 
}
  
 
}
 
}
</pre>
+
&lt;/pre&gt;

Revision as of 23:13, 23 November 2010

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>

Personal tools