-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.js
35 lines (26 loc) · 784 Bytes
/
test.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
'use strict'
const {NFC, NFCReader} = require('./index')
// Core API:
let nfc = new NFC();
console.log(nfc.listDevices())
nfc.close();
// Reader API:
let nfcReader = new NFCReader();
nfcReader.open("pn532_uart:/dev/tty.usbserial"); // or nfcReader.open(); to open the default device
nfcReader.poll(); // polls for the next card
nfcReader.on('card', card => {
console.log(card);
async function process() {
// Sending data:
// let result = await nfcReader.transceive(Buffer.from([0]));
// console.log(result);
await nfcReader.release();
console.log('card released');
nfcReader.poll(); // polls for the next card
}
process();
});
// triggered if polling has failed
nfcReader.on('error', err => {
throw err;
})