JSP and JavaBean

Hi all

I am using following JSP page to send the command to RFID reader and getting response from the reader.

<%@ page language="java" %>

<%@ page import="java.util.*"%>

<jsp:useBean id="readerIF5" class="RFIDReaders.IF5.IF5Reader" scope="session"/>

<jsp:setProperty name="readerIF5" property="*"/>

<%

// Sending commands to reader

String comm ="READ ANT COUNT REPORT=EVENT";

readerIF5.ReadIF5(comm);

%>

<%

// Getting tag data from reader

String Data = readerIF5.getData();

out.println(Data);

%>

<jsp:include page="sendIF5.jsp" />

Following is javabean

package RFIDReaders.IF5;

import com.intermec.datacollection.rfid.BasicBRIReader;

import com.intermec.datacollection.rfid.BasicReaderEvent;

import com.intermec.datacollection.rfid.BasicReaderException;

import com.intermec.datacollection.rfid.BasicTagEventListener;

import javax.servlet.http.*;

publicclass IF5Readerimplements HttpSessionBindingListener{

private String IP;

private String portStr;

private String Address;

String DATA;

String Command;

BasicBRIReader IMacReader =new BasicBRIReader();

/**

* Constructor

*/

public IF5Reader(){

}

/*

* Connect method to mak connection with IMac Reader..

*/

publicvoid ConnectIF5(String address){

try{

IMacReader.open(address);

}

catch(BasicReaderException ex){

ex.printStackTrace();

}

}

// Send command and get Tag Data.

String rData ="\n";

publicvoid ReadIF5(String Command)throws BasicReaderException{

IMacReader.addTagEventListener(new BasicTagEventListener(){

publicvoid tagEvent(BasicReaderEvent Event){

rData += Event.getTagDataString() +"\n";

setData(rData);

}

});

try

{

IMacReader.execute(Command);

Thread.sleep(1000);

}

catch(InterruptedException e){

e.printStackTrace();

}

}

// Response from Reader.

public String simpleRead(String Address, String cmd){

String Response =null;

try

{

ConnectIF5(Address);

Response = (IMacReader.execute(cmd));

}

catch (BasicReaderException ex)

{

ex.printStackTrace();

}

return Response;

}

// Setting tag data string.

privatevoid setData(String DATA){

this.DATA = DATA;

}

// Getting tag data string.

public String getData(){

return DATA;

}

// Closing Reader connection.

publicvoid CloseIF5(){

try{

IMacReader.removeTagEventListener(null);

IMacReader.close();

}

catch(BasicReaderException ex){

ex.printStackTrace();

}

}

publicvoid valueBound(HttpSessionBindingEvent evt){}

publicvoid valueUnbound(HttpSessionBindingEvent evt){}

}

Now my problem is that when its prints data it did not clear the old data but it prints old as well as new data.

I mean if send the commnad first time it print as follows

H02000000000000000151F503 1 1 H02000031323334000151E62B 1 1

and if i send the command again, we can see below that it prints old data (bold) as well as new data together.I just want to clear the old data and prints only the new data.H02000000000000000151F503 1 1 H02000031323334000151E62B 1 1 H02000031323334000151B775 1 1 H02000000000000000151F503 1 1

H02000000000000000151F503 1 1 H02000031323334000151E62B 1 1

H02000031323334000151E62B 1 1

Thanx

kvijai

[6831 byte] By [kvijaia] at [2007-11-26 16:32:13]
# 1

Hi all

Please have a look and let me know where i am making mistakes that it prints new as well as old data. I think, may be there is some tricks in String concatenation, becoz if i remove the string concatenation i can see only line of output at per click. For example either H02000000000000000151F503 1 1 or H02000031323334000151E62B 1 1

per call. But it has to print it together as the RFID reader detetcs both tag datas.

Thanx

kvijai

kvijaia at 2007-7-8 22:56:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi KviJai,

I read your code and I suggest you use a different BRI command to achieve what you want. The command "READ ANT COUNT REPORT=EVENT" will cause the reader to send each tag data as an asynchronous event message. The problem is that you are trying use the getData method to get the tags while the events may or may not occur at the time getData is called.

From the JSP code, I don't see a good reason for using events to report the tags. Also when you put the reader into this mode, the reader will be constantly reading and you will need to issue a "READ STOP" command to stop the read. I suggest you use the "READ ANT COUNT" command which is a synchronous command. The reader will do a singleshot read and return all tag data in the command response. You will not need to implement the BasicTagEventListener. Instead the tag data will be returned in the Response variable of the following code:

Response = (IMacReader.execute(cmd));

Hope this suggestion helps.

Ruth

ruthhsua at 2007-7-8 22:56:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thank you very much ruthhsu

what I expected is getting using only

Response = (IMacReader.execute(comm));

(1)But I wanna implement the response in the following table format.

TagIDRead CountANTENNA

H02000031323334000151B775 1 1

H02000000000000000151F503 1 1

H02000031323334000151E62B 1 1

If you have any idea, please help me.

(2) I wanna make a submit buttom from JSP to set the reader ATTRIBUTE such as setRDTRIES etc. so how to do it.

(3)Finally I wanna determine the ratio of Successful Read Counts to Read Try.

I hope you are fully famiar with BRI commands so you can easily provide me your suggestion to implement it.

Thanx

kvijai

kvijaia at 2007-7-8 22:56:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...