일주일 전에 NFC 리더 (PN532 I2C)와 5 개의 NFC 태그 (NTAG216)를 구입했습니다. 목표는 Java 인터페이스를 만드는 것이므로 프로젝트에 Java를 사용할 수 있습니다. . 인터페이스가 예상대로 작동하지만 NTAG216이 지원하는 모든 명령 (NTAG216 data sheet 32 페이지)을 시도하면 읽기, 쓰기 및 COMP_WRITE 만 작동합니다. 이 인터페이스에 의해 발생하지 않습니다, 나는 또한 C에서 시도했지만, 동일한 결과. 그래서, 내 명령에 어떤 실수가 있습니까? 아니면 libNFC가 어떤 식 으로든이 명령들이 실행되는 것을 방지합니까?
나쁜 영어로 유감스럽게 생각합니다. 제 문제가 여전히 이해되기를 바랍니다. 귀하의 답변libNFC는 READ, WRITE 및 COMP_WRITE 만 지원합니다.
감사합니다,
야콥
강령 :
public class Main {
public static void main(String[] args) {
System.load(new File("libNFC-JavaInterface.so").getAbsolutePath());
Context context = new Context();
Device device = new Device(context);
Target target = new Target();
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106), null,
target);
int[] response;
System.out.print("UID: ");
try {
System.out.printf("%014X", getUID(device));
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
System.out.print("Version: ");
try {
response = getVersion(device);
for (int i = 0; i < response.length; i++) {
System.out.printf("%02X", response[i]);
}
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
System.out.print("Read: ");
try {
response = read(device, 0x08);
for (int i = 0; i < response.length; i++) {
System.out.printf("%02X", response[i]);
}
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
System.out.print("Fast Read: ");
try {
response = fastRead(device, 0x08, 0x11);
for (int i = 0; i < response.length; i++) {
System.out.printf("%02X", response[i]);
}
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
System.out.print("Write: ");
try {
write(device, 0x08, new int[] {0x41, 0x42, 0x43, 0x44});
System.out.print("SUCCESSFUL");
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
System.out.print("Compatibility Write: ");
try {
compatibilityWrite(device, 0x09, new int[] {0x45, 0x46, 0x47, 0x48});
System.out.print("SUCCESSFUL");
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
System.out.print("Read cnt: ");
try {
response = readCnt(device);
for (int i = 0; i < response.length; i++) {
System.out.printf("%02X", response[i]);
}
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
System.out.print("Read sig: ");
try {
response = readSig(device);
for (int i = 0; i < response.length; i++) {
System.out.printf("%02X", response[i]);
}
} catch (NFCException e) {
device.selectPassiveTarget(new Modulation(ModulationType.NMT_ISO14443A, BaudRate.NBR_106),
null, target);
System.out.print("FAILED");
}
System.out.println();
target.free();
device.close();
context.exit();
}
public static long getUID(Device device) throws NFCException {
int[] response = read(device, 0x00);
return (long) response[0] << 48 | (long) response[1] << 40 | (long) response[2] << 32
| (long) response[4] << 24 | (long) response[5] << 16 | (long) response[6] << 8
| (long) response[7] << 0;
}
public static int[] getVersion(Device device) throws NFCException {
int[] response = new int[8];
device.transceiveBytes(new int[] {0x60}, response, -1);
return response;
}
public static int[] read(Device device, int startPage) throws NFCException {
int[] response = new int[16];
device.transceiveBytes(new int[] {0x30, startPage & 0xFF}, response, -1);
return response;
}
public static int[] fastRead(Device device, int startPage, int endPage) throws NFCException {
int[] response = new int[((endPage &= 0xFF) - (startPage &= 0xFF) + 1) * 4];
device.transceiveBytes(new int[] {0x3A, startPage, endPage}, response, -1);
return response;
}
public static void write(Device device, int startPage, int[] data) throws NFCException {
int[] command = new int[6];
command[0] = 0xA2;
command[1] = startPage & 0xFF;
for (int i = 0; i < data.length; i++) {
command[2 + i] = data[i] & 0xFF;
}
device.transceiveBytes(command, new int[0], -1);
}
public static void compatibilityWrite(Device device, int startPage, int[] data)
throws NFCException {
int[] command = new int[18];
command[0] = 0xA0;
command[1] = startPage & 0xFF;
for (int i = 0; i < data.length; i++) {
command[2 + i] = data[i] & 0xFF;
}
device.transceiveBytes(command, new int[0], -1);
}
public static int[] readCnt(Device device) throws NFCException {
int[] response = new int[3];
device.transceiveBytes(new int[] {0x39, 0x02}, response, -1);
return response;
}
public static int[] readSig(Device device) throws NFCException {
int[] response = new int[32];
device.transceiveBytes(new int[] {0x3C, 0x00}, response, -1);
return response;
}
}
그리고 출력 다음
UID: 04675362D55681
Version: error libnfc.driver.pn532_i2c Application level error detected (127)
FAILED
Read: 41424344454647480000000000000000
Fast Read: error libnfc.driver.pn532_i2c Application level error detected (127)
FAILED
Write: SUCCESSFUL
Compatibility Write: SUCCESSFUL
Read cnt: error libnfc.driver.pn532_i2c Application level error detected (127)
FAILED
Read sig: error libnfc.driver.pn532_i2c Application level error detected (127)
FAILED
pn53x.c를 검색했을 때 다음과 같이 나타났습니다. if (pnd-> bEasyFraming) { abtCmd [0] = InDataExchange; ... } else { abtCmd [0] = InCommunicateThru; ... } 조금 더 살펴본 후 easyFraming을 비활성화하는 방법을 발견했습니다. nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, false); 이제 (GET_VERSION, FAST_READ, READ_CNT, READ_SIG)에 대해 비활성화하고 나머지는 활성화됩니다. READ_CNT를 제외한 모든 작업이 이제는 RF Transmisson 오류가 발생하지만 현재로서는 내 용도로만 사용 가능합니다. – ProbstDJakob
READ_CNT의 경우 NFC 태그에서 활성화되었는지 확인하십시오. 오류가 발생하지 않는 경우 (구성 페이지의 ACCESS 바이트에서 NFC_CNT_EN 비트를 1로 설정) –