Giter Site home page Giter Site logo

Error writing short text about nfccard-tool HOT 7 CLOSED

somq avatar somq commented on May 30, 2024
Error writing short text

from nfccard-tool.

Comments (7)

somq avatar somq commented on May 30, 2024

This error comes from ndef-lib and is pretty self explanatory MB flag (message begin) is missing.

Can try to encode the same message using nfccard-tool and compare raw tags byte per byte?

Also, you can try to log or breakpoint directly in the ndef-lib where I set the line stop in the link above.

Pretty hard to tell you more without a repro or any code...

from nfccard-tool.

Spooky12 avatar Spooky12 commented on May 30, 2024

I am using an ACR122 reader along with nfc-pcsc to read and write tags. And for the code to encode and write NDEF messages I'm using the same as your example, the only change I made is:

const message = [
  { type: 'text', text: myText, language: 'en' },
]

I tried to encode the text 'test' with both nfccard-tool and another program and this the buffer I get:

  • nfccard-tool: Buffer(211) [3, 209, 1, 7, 84, 2, 101, 110, 116, 101, 115, 116, 254, 0, 0, 0, 97, 103, 254, 0, 97, 110, 111, 116, 104, 101, 114, 32, 116, 97, 103, 254, 0, 0, 0, …] (there are 0 until the end)
  • Other program: Buffer(13) [3, 11, 209, 1, 7, 84, 2, 101, 110, 116, 101, 115, 116]

I also tried to encode the text 'testtest1' and I get the same buffer from both nfccard-tool and the other program: Buffer(18) [3, 16, 209, 1, 12, 84, 2, 101, 110, 116, 101, 115, 116, 116, 101, 115, 116, 49]

It looks like the message length is not added to the buffer when the text is <9 characters so the whole buffer is shifted by one.
I don't know why it happens but I'll look at the code of the prepareBytesToWrite method to try to find out why.

from nfccard-tool.

Spooky12 avatar Spooky12 commented on May 30, 2024

I found out why it happens, it's because of this:

let NDEFMessageLength = NDEFMessage.toByteArray().length; // second and final write
let NDEF_MESSAGE_TLV_L_LENGTH = new Buffer(NDEFMessageLength.toString(16), 'hex'); // 0x00 - first write

When I want to encode a short message (<9 characters), NDEFMessageLength < 16 so NDEFMessageLength.toString(16) length is 1 so there is an error when the buffer is created.

But if I add a 0 before then it works fine.

E.g. if I have NDEFMessageLength=15 then NDEFMessageLength.toString(16) is 'f' which will create an error at the creation of the buffer but if I add 0 before to get '0f' then it works fine, the NDEF message is correct and I don't get NdefExceptionMessages.ExMessageBeginMissing when I try to read my tag.

from nfccard-tool.

somq avatar somq commented on May 30, 2024

Ok, I dug this one a bit and you are right.
This error comes from a wrong conversion of decimal to hex.
Anyway Buffer constructor usage is deprecated and these tricky converts are not ideal.
Si I'm replacing by a standard Buffer.from and everything should be OK.

I will commit a package update as well as a fix asap, afterthen I will publish it to npm but it the meantime you should be able to test and work with master.

Let me know if everything is OK on your side...

from nfccard-tool.

Spooky12 avatar Spooky12 commented on May 30, 2024

Great, thank you!

from nfccard-tool.

somq avatar somq commented on May 30, 2024

Your welcome, published to npm aswell.
Let me know if it works properly whenever you can.

from nfccard-tool.

Spooky12 avatar Spooky12 commented on May 30, 2024

It works properly now, I can create NFC tags with messages that contain less than 9 characters, thanks.

from nfccard-tool.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.