我正在使用nfc-pcsc模块运行电子应用程序。当我将Android设备放在acr-122u附近时,会收到以下日志记录:
Running in development
18:52:19 – info: nfc module init
(node:30973) UnhandledPromiseRejectionWarning: Error: Cannot process ISO 14443-4 tag because AID was not set.
at ACR122Reader.handle_Iso_14443_4_Tag (/private/var/www/lab/electron-clientnfc/node_modules/nfc-pcsc/dist/Reader.js:566:26)
at ACR122Reader.handleTag (/private/var/www/lab/electron-clientnfc/node_modules/nfc-pcsc/dist/Reader.js:506:21)
at CardReader.Reader.reader.on (/private/var/www/lab/electron-clientnfc/node_modules/nfc-pcsc/dist/Reader.js:164:18)
(node:30973) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:30973) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
这是我的代码:
const { NFC } = require('nfc-pcsc');
const nfc = new NFC(); // optionally you can pass logger
nfc.on('reader', (reader) => {
console.log(`${reader.reader.name} device attached`);
reader.aid = 'F222222222';
reader.on('card', async card => {
console.log(`${reader.reader.name} card detected`, card);
});
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);
});
这有什么问题?