在我向 adafruit PN532 发送命令后:
00 00 ff 03 fd d4 14 01 17 00
我得到答案:
00 00 C3 BF 00 C3 BF 00 00 00 C3 BF 02 C3 BE C3 95 15 16 00
代替:
00 00 ff 00 ff 00 00 00 ff 02 fe d5 15 16 00
我正在通过串行端口“/dev/ttyAMA0”使用 uart 与 PN532 通信我有 Java 代码。使用 pi4j 从 GPIO 读取。你知道为什么我会得到这种混搭的答案吗?
这是我的代码:
public class NFCapp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
byte[] SAMConfiguration = {(byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0x03, (byte) 0xfd, (byte) 0xd4, (byte) 0x14, (byte) 0x01, (byte) 0x17, (byte) 0x00};
byte[] wakeUP = {(byte) 0x55, (byte) 0x55, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
final byte[] ack = {(byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0x00, (byte) 0xff, (byte) 0x00};
final Serial serial = SerialFactory.createInstance();
try {
serial.open("/dev/ttyAMA0", 115200);
serial.addListener(new SerialDataListener() {
@Override
public void dataReceived(SerialDataEvent event) {
String data = event.getData();
StringBuilder buffer = new StringBuilder();
byte[] array = data.getBytes();
System.out.println("Read: ");
for (int i = 0; i < array.length; i++) {
System.out.printf("%02X ", array[i]);
}
serial.write(ack);
}
});
System.out.println("Port Opened: " + serial.isOpen() + " ");
serial.write(wakeUP);
System.out.print("Write: ");
for (int i = 0; i < SAMConfiguration.length; i++) {
System.out.printf("%02X ", SAMConfiguration[i]);
}
System.out.println();
serial.write(SAMConfiguration);
for (;;) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
System.out.println(ex.getMessage());
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
serial.close();
}
}