-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (44 loc) · 1.32 KB
/
app.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
51
52
const {NFC} = require('nfc-pcsc');
const {execHaloCmdPCSC} = require('@arx-research/libhalo/api/desktop.js');
const nfc = new NFC();
// list of HaLo commands that will be executed
// once the tag is detected by the reader
let commands = [
{
"name": "sign",
"message": "010203",
"keyNo": 1
},
{
"name": "sign",
"message": "05050505",
"keyNo": 1
}
];
nfc.on('reader', reader => {
reader.autoProcessing = false;
reader.on('card', card => {
(async () => {
// the card was detected, we can execute some HaLo commands
// please note you can call execHaloCmdPCSC() multiple times
// in order to execute multiple operations in a single tap
for (let command of commands) {
try {
let res = await execHaloCmdPCSC(command, reader);
// display the result
console.log(res);
} catch (e) {
// display the error
console.error(e);
}
}
})();
});
reader.on('error', err => {
console.log(`${reader.reader.name} an error occurred`, err);
});
});
nfc.on('error', err => {
console.log('An error occurred', err);
});
console.log('Tap the tag...');