Skip to content

Instantly share code, notes, and snippets.

@nadilas
Forked from Jonty/readtag.c
Last active September 14, 2018 18:12
Show Gist options
  • Save nadilas/c7a0b27fe178bb2f9755637310b5a299 to your computer and use it in GitHub Desktop.
Save nadilas/c7a0b27fe178bb2f9755637310b5a299 to your computer and use it in GitHub Desktop.
Read a single tag UID using libnfc.
#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