问题
I am using the ACR122U NFC reader in a java program that uses NFC cards. But by default the reader buzzes when it reads a card. I am trying to turn it off by without success the NFC reader documentation (found here: http://www.acs.com.hk/download-manual/419/API-ACR122U-2.03.pdf )shows that you can turn off the buzzer. But I am having trouble writing a java method for it. As you can see my class already has methods that communicate with the NFC reader. But I have be unable to convert the commands shown in the documentation into a java method.
NFCcard class :
package dataStores;
import java.util.List;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import javax.smartcardio.TerminalFactory;
public class NFCcard {
private TerminalFactory factory;
private List<CardTerminal> terminals;
private CardTerminal terminal;
private Card card ;
public CardChannel cardChannel;
public NFCcard() throws CardException {
factory = TerminalFactory.getDefault();
terminals = factory.terminals().list();
terminal = terminals.get(0);
card = terminal.connect("*");
cardChannel = card.getBasicChannel();
cardChannel.transmit( new CommandAPDU(new byte[] { (byte)0xE0, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0x01,(byte)0x77 }));
}
public String getCardID() throws CardException{
String cardID = "";
ResponseAPDU answer=cardChannel.transmit( new CommandAPDU(new byte[] { (byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00 }));
byte r[] = answer.getData();
for (int i=0; i<r.length; i++)
cardID+=r[i];
return cardID;
}
}
回答1:
You could try something like this :
byte buzzerOn = (byte)0xFF;
byte buzzerOff = (byte)0x00;
byte clazz = (byte)0xFF;
byte ins = (byte)0x00;
byte p1 = (byte)0x52;
byte p2 = buzzerOff;
byte le = (byte)0x00;
byte[] apdu = new byte[]{clazz,ins,p1,p2,le};
ResponseAPDU answer = cardChannel.transmit( new CommandAPDU(apdu));
byte successSW1 = (byte)0x90;
byte successSW2 = (byte)0x00;
if(answer.getSW1() == successSW1 && answer.getSW2() == successSW2){
//done
}else{
//failed
}
Response must be 90 00
来源:https://stackoverflow.com/questions/41535054/turning-off-the-buzzer-on-nfc-reader-nfc-acr122u-in-java