Jarda Hrbacek
Jarda Hrbacek

Reputation: 21

Get UID tag in WebUSB in node - Reader ACR122u

I am building a node application, which should read information from an NFC reader connected through USB. I´m able to power up the device, I can read ATR, but unable to read UID of a card, when the card is connected.

I´m starting with node-usb and it gives me an instance of webUSB

    import { usb, getDeviceList, findByIds } from 'usb';
    import usbLib from 'usb';
    import { findBySerialNumber, WebUSBDevice } from 'usb';

const device= findByIds( 0x072F, 0x2200);  // Find usb device by ID

      const webDevice = await WebUSBDevice.createInstance(device);
  webDevice.open(); 
  webDevice.selectConfiguration(1);                           // open device
  webDevice.claimInterface(0);                                // claim interface

let powerUpDevice  = new Uint8Array([0x62,0x00,0x00,00x00,0x00,0x00,0x01,0x00,0x00]).buffer;

await webDevice.transferOut(2, powerUpDevice);  // powerUp => o.k.

//reading endpoint after poweringup
let result = await webDevice.transferIn(2, 64);
  console.log(result.data.buffer);

result in console :

ArrayBuffer { [Uint8Contents]: <80 14 00 00 00 00 00 00 81 00 3b 8f 80 01 80 4f 0c a0 00 00 03 06 03 00 01 00 00 00 00 6a>, byteLength: 30 }

it is the right ATR if the reader detects a PICC. But now I want to read the UID tag of the inserted card. After reading and researching I´m lost. Maybe there should be some control transfer and then I should be able to read the UID tag.

something like this:

 let setup =    {
    requestType: 'class',
    recipient: 'interface',
    request: 0x00,
    value: 0x00,
    index: 0x00
        }    ;

        let abc = await webDevice.controlTransferOut(setup);

        const getCardUID = new Uint8Array([0xff,0xca, 0x00, 0x00, 0x04]).buffer;
        let getUID = await webDevice.transferOut(2, getCardUID);

        result = await webDevice.transferIn(2, 64);
        console.log(result.data.buffer);

running it returns nothing. Can anyone help me?

Thank You!

Upvotes: 0

Views: 466

Answers (0)

Related Questions