简体   繁体   English

用Raspberry书写后电话识别NFC标签错误

[英]Phone recognize NFC tag wrong after writing with Raspberry

So I have some NTAG216 tag from NXP. 所以我有一些NXP的NTAG216标签。 They have 888 bytes memory. 他们有888个字节的内存。 If they are used just with my Android application the phone recognise them as 888 bytes. 如果仅与我的Android应用程序一起使用,则手机会将其识别为888字节。 But after I write some message to them with my Raspberry Pi using libnfc the phone recognizes them as 238 bytes long (both the phone and the Pi uses the NDEF format and writes just the user memory of the tag). 但是,当我使用libnfc用Raspberry Pi向他们发送一些消息后,电话将它们识别为238个字节长(电话和Pi都使用NDEF格式并只写标签的用户内存)。 The Pi can read back its messages and can use the whole 888 bytes of memory, unlike the phone :/, the phone can only read the message if it is shorter than 238 bytes... (I am using the compatibility write mode of the NTAG216 with the Pi) Pi可以回读其消息并可以使用整个888字节的内存,这与电话:/不同,电话只有在短于238字节的情况下才可以读取消息...(我使用的是兼容性写模式NTAG216与Pi)

Does anyone has idea what is wrong? 有人知道哪里出了问题吗?

So I have found some explanation for this problem. 所以我找到了这个问题的一些解释。 And created some sort of solution. 并创建了某种解决方案。

The problem is that the function in the android`s NFC library always creates an NDEF short message and the message length is stored in one byte. 问题在于,Android的NFC库中的函数始终会创建NDEF短消息,并且消息长度存储在一个字节中。 Which means the maximum length is just 256 byte with the ndef part. 这意味着ndef部分的最大长度仅为256字节。 Why the NXP-s OWN program discover this tag just as 238 bytes... Well because it definitely has some errors inside, well better android have some serious issue handling NFC, becaus with a microsoft Lumia this tags dicovered as 888 bytes long without any problem. 为什么NXP-s OWN程序会发现这个标签只有238个字节...好吧,因为它内部肯定有一些错误,更好的android系统在处理NFC时会遇到一些严重的问题,因为使用Microsoft Lumia,这个标签被发现为888个字节长而没有任何问题。

Finally, the solution is use advanced NFC classes and write it from byte to byte. 最后,解决方案是使用高级NFC类并将其逐字节写入。 It will grant better understanding how this whole NFC works. 它将更好地理解整个NFC的工作原理。 With this you can create your own message protocol a bit better than this NDEF thing. 这样,您可以创建自己的消息协议,这比NDEF更好。 For me the solution was to use an extra four bytes at the end of the memory. 对我来说,解决方案是在内存末尾使用额外的四个字节。 With this I can adress much longer messages (2^32)than this tags can store. 这样,我可以获得比此标签可以存储的更长的消息(2 ^ 32)。 I also indicate in this four bytes if Ndef is present in the tag, becaus in this case I have to cut the first 7bytes of the message. 我还要在这四个字节中指示标签中是否存在Ndef,因为在这种情况下,我必须剪切消息的前7个字节。 And yes as you may found out I have create the ndef part of the message manually (for compatibility I need some part of the message to be readable with any application). 是的,您可能会发现,我已经手动创建了消息的ndef部分(为了兼容,我需要消息的某些部分才能被任何应用程序读取)。 I write just short messages, because the long messages of android and Lumia is different (Lumia can`t read what android has written and vice versa). 我只写短消息,因为android和Lumia的长消息是不同的(Lumia无法读取android编写的内容,反之亦然)。

So have a good time with programming if you want to use the whole memory with android and use the nfc advanced :). 因此,如果您想将整个内存与android一起使用并使用nfc advanced :),请在编程时花点时间。 I hope it will be easier in Windows Phone OS. 我希望在Windows Phone OS中会更轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM