I'm trying to access the ACS chip reader (ACR1252) from node.js using node-usb library. But it seems the library is really a usage pain due no documentation. So far I got the device recognized and connect to the interfaces (just on mac, linux still not working).
When a chip is identified, the device emits <Buffer 50 03>
and <Buffer 50 02>
when the chip is removed.
However when sending a command to get the chip's serial number, the transfer call fails with error undefined
.
This is my code so far:
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);
});
});
Output logs:
-- Received data: <Buffer 50 03>
Chip recognized!
transfer error undefined
-- Received data: <Buffer 50 02>