-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get nfc tag uid #76
Comments
Hi @quocnguyen123, in order to get UID of NFC tag, you need to send an appropriate APDU command ( You can do it like this: // ... connection to the reader and detecting card code as shown in README
// APDU CMD: Get Data
const packet = new Buffer([
0xff, // Class
0xca, // INS
0x00, // P1: Get current card UID
0x00, // P2
0x00 // Le: Full Length of UID
]);
reader.transmit(packet, 12, (err, response) => {
if (err) {
console.log(err);
return;
}
if (response.length < 2) {
console.log(`Invalid response length ${response.length}. Expected minimal length was 2 bytes.`);
return;
}
// last 2 bytes are the status code
const statusCode = response.slice(-2).readUInt16BE(0);
// an error occurred
if (statusCode !== 0x9000) {
console.log('Could not get card UID.');
return;
}
// strip out the status code (the rest is UID)
const uid = response.slice(0, -2).toString('hex');
// const uidReverse = reverseBuffer(response.slice(0, -2)).toString('hex'); // reverseBuffer needs to be implemented
console.log('card uid is', uid);
}); If you don't want to deal with these underlying things, take a look at nfc-pcsc library. It offers easy to use high level API for detecting, reading and writing NFC tags and cards, also supports Promises and async/await. Hope it helps. |
I solved this issue with your direction. Thank you very much |
You should set the protocol, if needed, during connect. https://github.com/martinpaljak/esteid.js/blob/master/node-pcsc.js#L82 |
How can i get uid (unique ID) of NFC tag? Help me please!
The text was updated successfully, but these errors were encountered: