【发布时间】:2018-10-10 10:20:52
【问题描述】:
我正在尝试使用 node-usb 库从 node.js 访问 ACS 芯片阅读器 (ACR1252)。但是由于没有文档,该库似乎确实是一种使用痛苦。到目前为止,我已识别设备并连接到接口(仅在 mac 上,linux 仍然无法正常工作)。
当芯片被识别时,当芯片被移除时,设备会发出<Buffer 50 03>和<Buffer 50 02>。
但是在发送命令获取芯片序列号时,传输调用失败,错误为undefined。
这是我目前的代码:
import usb, { InEndpoint, OutEndpoint } from 'usb';
usb.on('attach', device => {
device.__open();
device.__claimInterface(0);
device.open();
const ifc = device.interface(0);
ifc.claim();
const outEndpoint: OutEndpoint = <OutEndpoint>ifc.endpoints[0];
const inEndpoint: InEndpoint = <InEndpoint>ifc.endpoints[2];
inEndpoint.startPoll();
inEndpoint.on('data', (buffer: Buffer) => {
console.warn('-- Received data: ', buffer);
if (buffer.toString('hex') === '5003') {
console.warn('Chip recognized!');
outEndpoint.transfer(Buffer.from('FF CA 00 00 00', 'hex'), error => {
console.warn('transfer error', error);
});
}
});
inEndpoint.on('error', error => {
console.warn('error', error);
});
});
输出日志:
-- Received data: <Buffer 50 03>
Chip recognized!
transfer error undefined
-- Received data: <Buffer 50 02>
【问题讨论】:
标签: node.js usb libusb smartcard-reader node-usb