'NFC read on ACS ACR122U

I have the ACS ACR122U NFC reader/writer and trying to use it with NodeJs and the pcsclite module.

I followed the reader's API manual for authentication.

In most cases I receive the desired data - 90 00 (success) for authentication and the string from the card.

However in some cases I receive 63 00 (error) for both authentication and card reading, and in some cases 90 00 for the authentication but 63 00 for the read. Unfortunately it happens too often, and when it happens it often happens on a lot of consecutive reads, so I want to limit the number of errors. I have tried with a timer between the authentication and read, but it only seems to make the problem worse.

This is my code:

  reader.on('status', function(status) {
    console.log('Status(', this.name, '):', status);
    /* check what has changed */
    var changes = this.state ^ status.state;
    if (changes) {
      if ((changes & this.SCARD_STATE_EMPTY) && (status.state & this.SCARD_STATE_EMPTY)) {
          console.log("card removed");/* card removed */
          reader.disconnect(reader.SCARD_LEAVE_CARD, function(err) {
              if (err) {
                  console.log(err);
              } else {
                  console.log('Disconnected');
              }
          });
      } else if ((changes & this.SCARD_STATE_PRESENT) && (status.state & this.SCARD_STATE_PRESENT)) {
        console.log("card inserted");/* card inserted */
        reader.connect({ share_mode : this.SCARD_SHARE_SHARED }, function(err, protocol) {
            if (err) {
                console.log(err);
            } else {
              console.log('Protocol(', reader.name, '):', protocol);
              
              reader.transmit(new Buffer.from([0xFF, 0x88, 0x00, 0x01, 0x60, 0x00]), 255, protocol, function(err, data) {
                  if (err) {
                      console.log(err);
                  } else {
                    console.log('Data received ', data);
                    reader.transmit(new Buffer.from([0xFF, 0xB0, 0x00, 0x01, 0x10]), 255, protocol, function(err, data) {
                      if (err) {
                        console.log(err);
                      } else {
                        console.log('Data received2', data);                          
                        // reader.close();
                        pcsc.close();
                      }
                    });  
                  }
              });
            }
        });
      }
    }
  });
});

Any suggestions are appreciated. Thanks!



Solution 1:[1]

I switched to the nfc-pcsc library from the same author instead, which seems to be a lot better and more maintained...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kasper Sommer