valentiniljaz / cordova-nfcv-plugin

Cordova plugin for reading and writing to NFC tags using NfcV protocol (with support for Ionic2)
14 stars 9 forks source link

gettting error in nfcv read #4

Closed rohan061 closed 6 years ago

rohan061 commented 6 years ago

screenshot_20171109-092842 Hi i am getting the above errro while writng this code in cordova.

NfcV.readBlock([ { block: new Uint8Array([0x18]) }, { block: new Uint8Array([0x19]) } ],

function(data) { alert(data); },

  function(err) {
            alert(err);

});

valentiniljaz commented 6 years ago

Hello!

Can you provide more context around the above code? Can you paste your whole controller/service class. It will be much easier for me to debug.

Can you also provide versions of Cordova, Ionic, Angular etc.

Best regards, Valentin

valentiniljaz commented 6 years ago

I think I see what's the problem. You are trying to read multiple blocks at once, but you cannot do that using method NfcV.readBlock. You can only read one block at a time with the above method. I implemented a method for reading multiple blocks but it's written in TypeScript. Check out NfcvService.read.

If you are not using Ionic with Angular, then you can have a look at method onDeviceReady in post https://github.com/valentiniljaz/cordova-nfcv-plugin/issues/3#issuecomment-313151826 The above code implements basic reading of just one block using Cordova (without Ionic and Angular).

The basic 2 steps needed to communicate with NfcV are: 1) startListening for Nfc intent 2) when the intent is received then you issue a read command for one block and then the next one and so on

If you need to read more then one block in just one go (during one intent), you need to chain the reads. The best way to do that is to use promises, because each read command is async operation. When all the promises resolve you get the data for all blocks.

Best regards, Valentin

rohan061 commented 6 years ago

Thank you very much sir. You saved my lots of time.