Skip to content

Instantly share code, notes, and snippets.

@Jonty
Created October 18, 2010 14:40
Show Gist options
  • Save Jonty/632315 to your computer and use it in GitHub Desktop.
Save Jonty/632315 to your computer and use it in GitHub Desktop.
Read a single tag UID using libnfc.
#include <nfc/nfc.h>
#include <nfc/nfc-messages.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;
}
@kafffee
Copy link

kafffee commented Oct 14, 2018

Hello I have a problem compiling this. It says: fatal error: nfc/nfc-messages.h: file.or folder not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment