在Java中关闭NFC阅读器(NFC ACR122U)上的蜂鸣器 [英] Turning off the buzzer on NFC reader ( NFC ACR122U) in Java
问题描述
我正在使用NFC卡的Java程序中使用ACR122U NFC读取器.但是默认情况下,读卡器在读取卡时会发出嗡嗡声.我试图通过NFC阅读器文档(未找到成功)将其关闭(请参见: http://www.acs.com.hk/download-manual/419/API-ACR122U-2.03.pdf )显示您可以关闭蜂鸣器.但是我在为它编写Java方法时遇到了麻烦.如您所见,我的班级已经有与NFC阅读器通信的方法.但是我无法将文档中显示的命令转换为java方法.
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类:
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;
}
}
推荐答案
您可以尝试以下方法:
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
这篇关于在Java中关闭NFC阅读器(NFC ACR122U)上的蜂鸣器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!