Linux vs. Windows injecting buffer values

injecting buffer values gives syntax error in Windows 10. If I use my Linux system at home, I can inject a buffer

buffer: [02,45,45,03]

Windows gives me "SyntaxError: Unexpected number in JSON at position 1"

I tried [\0x02,\0x45,\0x45,\0x03]

What is the proper means to put a buffer array in the inject?

I can't answer your main question as I don't use Windows for Node-RED, but just to check that you're aware that "0x45" isn't the same value as "45"...

You enter decimal values in an array format e.g. [2,69]

or to use hex then you need quotes ["0x02","...

I'm wondering if the leading zero in the OP's first example is causing a problem, although I have no idea why. It should be accepted, unless it's being interpreted as octal or something.

yes, @molesworth thanks... i have an ascii table.

Thanks for the "Quotes" resopnse... Who knew that you would need quotes and not an escape ""?... I found that Linux and Windows works the same... It was that I put in a number not beginning in 0, NULL "00" just "0"... Maybe this is a good time to take a look at these rules and maybe put them in the "HELP" tab where for common and uncommon injection rules, you might be able to find a hint.

Maybe allow to enter values that have leading zeros to a buffer... and since the "" is an escape , maybe allow that for hex values.

Kind Regards,
@hp_apcc

Dave loves pull requests :wink:

Is that THE way to offer suggestions to the "Help" tab? I kind of figure, if @dceejay is spending a lot of time on the forum answering questions, he may want to not answer the same ones over and over, but maybe the answers can make their way into the "Help" tab....

Examples are really great to get you where you need to be. Just an example of each kind of data, or something that is not the run of the mill. like Buffer: ["0x02","0x0D","0x0A","0x03"] ... [2,56,65,0,3]

I spent way too much time on this one trying to figure out what I did wrong. I try to not bother the forum with the minutia that I should be able to find or read the documentation on my own. I could not find anywhere an example of how to properly structure a buffer with the hexadecimal values to test my printer communication.

Yes it is the most helpful way, that way I can spend more time with my family, rather than writing help files for standard JavaScript..

It is a suggestion... Not meant at all in disrespect. By the way... you cannot declare a buffer in js with var mybuf= ["0x02","0x00","0x03"]; yields a string array... :thinking: so that is not "standard JavaScript"...

What is not standard javascript about that? What else could it yield other than an array of strings?

that is standard javascript/nodejs to declare an array... but that's not how you declare a buffer - try var mybuf= Buffer.from(["0x02","0x00","0x03"]);
but yes - happy to consider a PR to the help info with simple example

I think perhaps I misunderstood what you meant. If you say you want a buffer containing those hex numbers then indeed it is entirely standard JS to say
var mybuf= Buffer.from(["0x02","0x00","0x03"]);

Great to hear from you both! I was not aware that I needed the buffer class function to find the syntax. I did not know where to look. I found a reference to an escape \0x… And my point isn’t that you are not correct about the “”, it’s that you cannot draw a straight line between the class function call, (unless noted in help tab….) and applying it in an inject. It’s not native JavaScript, it’s a class function. of course if you invoke the entire realm to be correct, great you win!

Not to worry, my point is only this. Can you please consider updating the help tab for Inject and any other “native” nodes to include the lesser traveled nuances in syntax in order to give us common folk a hint?

You are right, the Buffer class is not part of the javascript spec, but it is part of the nodejs javascript spec.
However, you said in the first post that you wanted to inject a Buffer object. It is difficult to see how that would be possible without the use of the Buffer class.

Why are you asking me in particular to amend the docs (I am not a developer)? Anyone can do it. If you think there is an addition that would be helpful then please get involved and submit a PR.

I’m not asking you. I am asking @dceejay. You happened to chime in with @dceejay. I was also told I need to do a pull request. This is next. It’s not a mission and I don’t need to make a big deal. I’m very happy with this. I only wanted to make a suggestion to help others that find themselves in similar instances.

OK, sorry. You replied to my post so I assumed you meant me.

Having people help with docs is great.

1 Like

Ok. I think I can certainly help with that. Tell me where to submit my drafts and I’ll start with the inject node. Ill just start with this suggestion and go from there. I will need you to correct and add content.