Improve README
This commit is contained in:
124
README.md
124
README.md
@@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
Bindings over pcsclite to access Smart Cards. It works in **Linux**, **macOS** and **Windows**.
|
Bindings over pcsclite to access Smart Cards. It works in **Linux**, **macOS** and **Windows**.
|
||||||
|
|
||||||
> **Looking for library to work easy with NFC tags?**
|
> 📌 **Looking for library to work easy with NFC tags?**
|
||||||
take a look at [nfc-pcsc](https://github.com/pokusew/nfc-pcsc) which offers easy to use high level API for detecting / reading and writing NFC tags and cards
|
> take a look at [nfc-pcsc](https://github.com/pokusew/nfc-pcsc) which offers easy to use high level API
|
||||||
|
> for detecting / reading and writing NFC tags and cards
|
||||||
|
|
||||||
|
|
||||||
## Content
|
## Content
|
||||||
@@ -61,8 +62,12 @@ Once you have all needed libraries, you can install using npm:
|
|||||||
npm install @pokusew/pcsclite --save
|
npm install @pokusew/pcsclite --save
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
> 👉 **If you'd prefer an easy to use high level API** for detecting / reading and writing NFC tags and cards,
|
||||||
|
> take a look at [nfc-pcsc](https://github.com/pokusew/nfc-pcsc).
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const pcsclite = require('@pokusew/pcsclite');
|
const pcsclite = require('@pokusew/pcsclite');
|
||||||
|
|
||||||
@@ -70,82 +75,83 @@ const pcsc = pcsclite();
|
|||||||
|
|
||||||
pcsc.on('reader', (reader) => {
|
pcsc.on('reader', (reader) => {
|
||||||
|
|
||||||
console.log('New reader detected', reader.name);
|
console.log('New reader detected', reader.name);
|
||||||
|
|
||||||
reader.on('error', err => {
|
reader.on('error', err => {
|
||||||
console.log('Error(', reader.name, '):', err.message);
|
console.log('Error(', reader.name, '):', err.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
reader.on('status', (status) => {
|
reader.on('status', (status) => {
|
||||||
|
|
||||||
console.log('Status(', reader.name, '):', status);
|
console.log('Status(', reader.name, '):', status);
|
||||||
|
|
||||||
// check what has changed
|
// check what has changed
|
||||||
const changes = reader.state ^ status.state;
|
const changes = reader.state ^ status.state;
|
||||||
|
|
||||||
if (!changes) {
|
if (!changes) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((changes & reader.SCARD_STATE_EMPTY) && (status.state & reader.SCARD_STATE_EMPTY)) {
|
|
||||||
|
|
||||||
console.log("card removed");
|
|
||||||
|
|
||||||
reader.disconnect(reader.SCARD_LEAVE_CARD, err => {
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Disconnected');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
else if ((changes & reader.SCARD_STATE_PRESENT) && (status.state & reader.SCARD_STATE_PRESENT)) {
|
|
||||||
|
|
||||||
console.log("card inserted");
|
|
||||||
|
|
||||||
reader.connect({ share_mode: reader.SCARD_SHARE_SHARED }, (err, protocol) => {
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Protocol(', reader.name, '):', protocol);
|
|
||||||
|
|
||||||
reader.transmit(Buffer.from([0x00, 0xB0, 0x00, 0x00, 0x20]), 40, protocol, (err, data) => {
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Data received', data);
|
if ((changes & reader.SCARD_STATE_EMPTY) && (status.state & reader.SCARD_STATE_EMPTY)) {
|
||||||
reader.close();
|
|
||||||
pcsc.close();
|
|
||||||
|
|
||||||
});
|
console.log("card removed");
|
||||||
|
|
||||||
});
|
reader.disconnect(reader.SCARD_LEAVE_CARD, err => {
|
||||||
|
|
||||||
}
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
console.log('Disconnected');
|
||||||
|
|
||||||
reader.on('end', () => {
|
});
|
||||||
console.log('Reader', reader.name, 'removed');
|
|
||||||
});
|
}
|
||||||
|
else if ((changes & reader.SCARD_STATE_PRESENT) && (status.state & reader.SCARD_STATE_PRESENT)) {
|
||||||
|
|
||||||
|
console.log("card inserted");
|
||||||
|
|
||||||
|
reader.connect({ share_mode: reader.SCARD_SHARE_SHARED }, (err, protocol) => {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Protocol(', reader.name, '):', protocol);
|
||||||
|
|
||||||
|
reader.transmit(Buffer.from([0x00, 0xB0, 0x00, 0x00, 0x20]), 40, protocol, (err, data) => {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Data received', data);
|
||||||
|
reader.close();
|
||||||
|
pcsc.close();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
reader.on('end', () => {
|
||||||
|
console.log('Reader', reader.name, 'removed');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pcsc.on('error', err => {
|
pcsc.on('error', err => {
|
||||||
console.log('PCSC error', err.message);
|
console.log('PCSC error', err.message);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Behavior on different OS
|
## Behavior on different OS
|
||||||
|
|
||||||
TODO document
|
TODO document
|
||||||
|
|||||||
Reference in New Issue
Block a user