嘿,伙计们,我想做一个叫"RFID管理系统“的项目
我从一些网站上找到了一些示例代码,并在其中添加了一些代码。
我的RFID现在可以从mifare卡中读取数字,但我已经面临一个问题:如何为我的RFID机器创建一个循环,以便在不按下Eclipse中的"RUN“按钮的情况下一次又一次地读取卡
import java.util.List;
import javax.smartcardio.*;
import javax.xml.bind.DatatypeConverter;
public class Blog {
public static void main(String[] args) {
try {
// Display the list of terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
// Use the first terminal
CardTerminal terminal = terminals.get(0);
// Connect wit hthe card
Card card = terminal.connect("*");
System.out.println("card: " + card);
CardChannel channel = card.getBasicChannel();
// Send Select Applet command
ResponseAPDU answer = channel.transmit(new CommandAPDU(new byte[] { (byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00 } ));
// Send test command
answer = channel.transmit(new CommandAPDU(new byte[] { (byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00 } ));
byte r[] = answer.getData();
String hex = DatatypeConverter.printHexBinary(answer.getBytes());
System.out.println("Response: " + hex);
// Disconnect the card
card.disconnect(false);
} catch(Exception e) {
System.out.println("Ouch: " + e.toString());
}
}
}发布于 2016-11-08 17:22:23
你可能知道arduino编程,对吧?,我们有一个循环函数(),所以我们在里面写的任何代码都会永远循环。这就是这些东西(如rfid、指纹扫描仪、温度传感器、运动检测器等)的逻辑。所以在这里使用相同的技术。将您的代码放在
while(1){
} 循环。这将永远迭代您的代码。因此,你将获得所需的o/p。你可以随心所欲地多次刷新你的卡。确保读取和处理数据的代码应该只出现在循环中。否则,它将占用大量内存,并可能导致代码崩溃。
https://stackoverflow.com/questions/40482958
复制相似问题