forked from pokusew/nfc-pcsc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwithout-auto.js
50 lines (33 loc) · 1.17 KB
/
without-auto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
// #############
// Alternative usage
// - see "Alternative usage" section in README for an explanation
// #############
import { NFC } from '../src/index';
const nfc = new NFC(); // optionally you can pass logger
nfc.on('reader', reader => {
// disable auto processing
reader.autoProcessing = false;
console.log(`${reader.reader.name} device attached`);
reader.on('card', card => {
// card is object containing following data
// String standard: TAG_ISO_14443_3 (standard nfc tags like MIFARE) or TAG_ISO_14443_4 (Android HCE and others)
// String type: same as standard
// Buffer atr
console.log(`${reader.reader.name} card inserted`, card);
// you can use reader.transmit to send commands and retrieve data
// see https://github.com/pokusew/nfc-pcsc/blob/master/src/Reader.js#L288
});
reader.on('card.off', card => {
console.log(`${reader.reader.name} card removed`, card);
});
reader.on('error', err => {
console.log(`${reader.reader.name} an error occurred`, err);
});
reader.on('end', () => {
console.log(`${reader.reader.name} device removed`);
});
});
nfc.on('error', err => {
console.log('an error occurred', err);
});