Android NFC writeNdefMessage throws IOException Tag is not ndef -
i'm developing nfc environment consisting of tag (as3953 chip + microcontroller) , smartphone (samsung galaxy fame runnung android 4.1.2).
while reading ndef message works i'm stuck on writing message tag. copied of code http://tapintonfc.blogspot.de/2012/07/the-above-footage-from-our-nfc-workshop.html , modified accept iso14443a tag type 4 searching tag techlist isodep, nfca , ndef in supportedtechs(). since of them listed app continues writetag():
public writeresponse writetag(ndefmessage message, tag tag) { try { ndef ndef = ndef.get(tag); if (ndef != null) { log.d(tag, "writetag: tag type: "+ndef.gettype()); ndef.connect(); log.d(tag, "writetag: connected!"); if (!ndef.iswritable()) { return new writeresponse(0, "tag read-only"); } if (ndef.getmaxsize() < message.tobytearray().length) { return new writeresponse(0, "size error"); } log.d(tag, "writetag: write ndef..."); ndef.writendefmessage(message); log.d(tag, "writetag: wrote ndef!"); if (writeprotect) ndef.makereadonly(); return new writeresponse(1, "wrote message pre-formatted tag."); } else { log.d(tag, "writetag: ndef==null!"); return new writeresponse(0, "writetag: ndef==null!"); } } catch (exception e) { log.d(tag, "writetag: exception: " + e.tostring()); return new writeresponse(0, "failed write tag"); } }
logcat shows:
11:08:46.400: onnewintent 11:08:46.400: supportedtechs: techlist: android.nfc.tech.isodep,android.nfc.tech.nfca,android.nfc.tech.ndef, 11:08:46.400: supportedtechs: tech supported! 11:08:46.400: writetag: tag type: org.nfcforum.ndef.type4 11:08:46.410: writetag: connected! 11:08:46.410: writetag: write ndef... 11:08:46.490: writetag: exception: java.io.ioexception: tag not ndef
as can see ioexception thrown saying tag not ndef contradicts techlist. looking further android code writendefmessage() tries tagservice , servicehandle tag match them against. fails exception thrown (no message written now):
public void writendefmessage(ndefmessage msg) throws ioexception, formatexception { ... infctag tagservice = mtag.gettagservice(); ... int servicehandle = mtag.getservicehandle(); if (tagservice.isndef(servicehandle)) { ... } else { throw new ioexception("tag not ndef"); } ... }
is there workaround or not possible @ kind of tag? i'm programming tag error might on other side, seems java problem.
edit 1:
i don't connect technology before there shouldn't opened connection. if open connection before ndef.connect() there illegalstateexception: close other technology first!
i configured as3953 iso14443a level-4 tag type 4 blocks forwarded microcontroller. i-blocks handled if there other commands µc has read out on spi port isn't case logic analysis. said reading ndef file works , tested 4kb file. looking @ logic analysis following steps made (all returning positive 9000-code):
(c=command, r=response) (corrected due renaming mistake) select name: c: 02 00 a4 04 00 07 d2 76 00 00 85 01 01 00 r: 02 90 00 select id - select cc file c: 03 00 a4 00 0c 02 e1 03 r: 03 90 00 read 0x0f bytes of cc file c: 02 00 b0 00 00 0f r: 02 00 0f 20 00 3b 00 34 04 06 e1 04 0f ff 00 00 90 00 select id - select ndef file c: 03 00 a4 00 0c 02 e1 04 r: 03 90 00 read 0x02 bytes (first 2 bytes apdu-size) c: 02 00 b0 00 00 02 r: 02 0f d3 90 00 read 0x3b bytes (frame size) of first part of ndef file (external type, jpeg image payload) c: 03 00 b0 00 02 3b r: 03 c4 0c 00 00 0f c1 64 65 2e 74 65 73 74 61 70 70 3a 61 01 ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 60 00 60 00 00 ff db 00 43 00 49 32 36 40 36 2d 49 40 3b 40 52 4d 49 56 6d 90 00 [ndef file] read 0x26 bytes of last part of ndef file c: 03 00 b0 0f ae 27 r: 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ff d9 00 00 90 00
using same app writing start activity filters nfcadapter.action_tag_discovered intents. in linked example phone touches tag calling onresume() doing mnfcadapter.enableforegrounddispatch(...);
when log spi communication same reading procedure above done. since logcat shows working intent dispatcher guess app stops @ ioexception, closing connection , going on read out android found tag again.
edit 2:
there might hint 1 of first interrupts issue deselect command handled as3953 itself:
(count * interrupt) 3 * power 1 * wake-up irq @ entry in active(*) state 1 * deselect command 1 * wake-up irq @ entry in active(*) state 1 * irq due start of receive
it works now. figured out startup routine checks , sets configuration word transmitted high baud rate as3953. worked reading must have been mixed writing tag.
i cannot tell sure if reason why didn't work. there problem slow reading of 32byte fifo waterlevel interrupts handled late - expected problem on android side since couldn't find write command in logic analysis , exception didn't describe reason enough.
thanks lot michael roland further debugging, still don't unterstand why tag read @ first if want write - there should workaround reading empty ndef message writing process done quickly.
for have work on firmware , cannot forecast further problems actual issue (ndef.writendefmessage()) returns successfully.
Comments
Post a Comment