-
-
Save nadilas/c7a0b27fe178bb2f9755637310b5a299 to your computer and use it in GitHub Desktop.
Read a single tag UID using libnfc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <nfc/nfc.h> | |
int main () | |
{ | |
nfc_device_t *nfcDev; | |
nfcDev = nfc_connect(NULL); | |
if (nfcDev == NULL) { | |
printf("Cannot connect to the RFID reader.\n"); | |
return 1; | |
} | |
nfc_initiator_init(nfcDev); | |
// This reader can only get one card ID, so there's no point looking for more | |
nfc_target_info_t targetInfo[1]; | |
int numTargets; | |
if (nfc_initiator_list_passive_targets(nfcDev, NM_ISO14443A_106, targetInfo, 1, &numTargets)) { | |
int uidPos; | |
for (uidPos = 0; uidPos < targetInfo[0].nai.szUidLen; uidPos++) { | |
printf("%02x", targetInfo[0].nai.abtUid[uidPos]); | |
} | |
printf("\n"); | |
} | |
nfc_disconnect(nfcDev); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment