chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
712 stars 568 forks source link

nfc.transceive returns 'Tag was lost.' #335

Closed marioshtika closed 6 years ago

marioshtika commented 6 years ago

Hello I want to get data from a device with NfcV.

I am using the below code and always getting an error message 'Tag was lost.'

nfc.addTagDiscoveredListener((nfcEvent) => {
  nfc.connect('android.nfc.tech.NfcV')
      .then(data => {
         let writeData = new Uint8Array(2);
         writeData[0] = 0x00;
         writeData[1] = 0x20;
         nfc.transceive(writeData.buffer)
         .then(response => {
             console.log('response: ' + response);
          })
         .catch(error => {
              console.log('error transceive: ' + JSON.stringify(error));
          });
      })
      .catch((error) => {
        console.log('connection failed', error)
      });
});

Can you help me? Am I doing something wrong?

marioshtika commented 6 years ago

I found out that the message 'Tag was lost.' is returned when the command that you are sending are not correct. Also the error in the above code is that I didn't send the address of the block writeData[2] = 0x00 (first block) and also the 'address' is as 16bit so the Uint8Array() should be (4)

let writeData = new Uint8Array(4);
writeData[0] = 0x00;
writeData[1] = 0x20;
writeData[2] = 0x00;
writeData[3] = 0x00;