我在使用NFC卡的java程序中使用ACR122U NFC读卡器。但默认情况下,读者在读卡时会发出嗡嗡声。我试图通过NFC阅读器文档(在此处找到http://www.acs.com.hk/download-manual/419/API-ACR122U-2.03.pdf)没有成功将其关闭,这表明您可以关闭蜂鸣器。但是我在编写java方法时遇到了麻烦。正如您所看到的,我的课程已经有了与NFC阅读器通信的方法。但是我无法将文档中显示的命令转换为java方法。
NFCcard类:
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;
}
}
答案 0 :(得分:0)
您可以尝试这样的事情:
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
}
回复必须为90 00