Comments (3)
Hi @quocnguyen123,
in order to get UID of NFC tag, you need to send an appropriate APDU command (Get Data
in this case, btw you can find some basic commands here) using reader.transmit
method and then parse the response.
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.
You just need a few lines to read card UID.
Hope it helps.
from node-pcsclite.
I solved this issue with your direction. Thank you very much
In line: reader.transmit(packet, 12, (err, response) I think we should pass protocol as third argument.
from node-pcsclite.
You should set the protocol, if needed, during connect. https://github.com/martinpaljak/esteid.js/blob/master/node-pcsc.js#L82
from node-pcsclite.
Related Issues (20)
- Fails to rebuild for electron 28+ (v8 12+) HOT 3
- Clean up branches on github
- Add a `ISO7816transmit` function close to the core implementation HOT 1
- How to switch from T0 to T1 without disconnecting ? HOT 7
- Error building on OS X HOT 3
- How do you list all readers, including internal ones? HOT 3
- Cannot install on windows (node 9.3 & npm 5.5.1) - HELP HOT 1
- electron and Ionic integration HOT 2
- Deprecated NAN API in use HOT 4
- Improper Handling of Response 6100 HOT 2
- Error: SCardTransmit error: Insufficient buffer with Expect Return length 0xFF HOT 1
- Electron fails to start pcsclite
- Can't compile it - Buffertools package went unmantained HOT 2
- Failed installation on OSX
- Bindings Errors in Vue.js HOT 1
- PCSC error SCardGetStatusChange error: The action was cancelled by an SCardCancel request. HOT 1
- Electron: Loading non-context-aware native module in renderer HOT 8
- Release memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE (function SCardListReaders) HOT 1
- Implement SCardGetReaderDeviceInstanceId() function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-pcsclite.