Hi all,
I am thankful to all who answered t my last questions
now this time i have issue withj nfc readers
I am working with ACR122U nfc reader,
when i plugin my acr device to pc i need a notification msg saying "new device found" similarly when i plug out the device i need a msg showing "reader disconnected"
but for me when i remove my device it showing the right msg
whereas when i plug in it shows first as "new device found"
and immediately it will show "reader disconnected"
so technically when ACR122 reader is ejected waitforchange() is getting triggered only one time but when i insert it is getting triggered multiple times thats why I am getting a multiple message I think so but how to control over it
any suggesstion plz,,,
here is my code snippet
public class WaitForChange {
static final Logger logger = Logger.getLogger(WaitForChange.class);
static int count=0;
private static List<String> terminalNames(List<CardTerminal> terminals)
throws Exception {
ArrayList<String> r = new ArrayList<String>(terminals.size());
HexBinaryAdapter hex = new HexBinaryAdapter();
byte[] CLA = { (byte) 0x80, 0x30, 0x00, 0x04 };
/*if(terminals.size()>1)
throw new Exception();*/
System.out.println("count "+count);
if(terminals.size()==1)
System.out.println(terminals.get(0).getName());
if(terminals.size()==0)
System.out.println("device removed");
if(terminals.size()>1)
System.out.println("more readers found");
for (int i = 0; i < terminals.size(); i++) {
if (terminals.get(i).isCardPresent()) {
Card card = terminals.get(i).connect("*");
}
r.add(terminals.get(i).getName());
}
return r;
}
public static void main(String[] args) throws Exception {
PropertyConfigurator.configure("log4j2.properties");
logger.debug("Main Thread");
logger.info("----PUGIN STARTED---");
TerminalFactory context;
CardTerminals terminals;
Security.addProvider(new Smartcardio());
context = TerminalFactory.getInstance("PC/SC", null,Smartcardio.PROVIDER_NAME);
terminals = context.terminals();
while (true) {
terminals.waitForChange();
List<CardTerminal> inserted = terminals.list(State.CARD_INSERTION);
count++;
terminalNames(inserted);
//s System.out.format("Card inserted in %s; cards removed from %s%n",
// terminalNames(inserted), terminalNames(removed));
}
}
}
ACR122U NFC reader
Moderators: Matt, kyle, Moderators
Who is online
Users browsing this forum: No registered users and 1 guest