How to add a carriage return to a buffer?

Hi all, I'm looking for a way to add a carriage return [0xd] at the end of my buffer array but can't figure out how.

For reference, here is my string to carriage function

var payload = msg.payload
b = Buffer.from(msg.payload);

msg.payload=b;

return msg;

I Tried adding a \r to my payload string but unfortunately, it's not working

It should work....
Try this

msg.payload = Buffer.from(msg.payload + "\r");
return msg;
[{"id":"bebb467a.c7e068","type":"inject","z":"fb2d52d1.30eaa","name":"","topic":"","payload":"Hello World","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":960,"wires":[["517a60f3.ad169"]]},{"id":"517a60f3.ad169","type":"function","z":"fb2d52d1.30eaa","name":"","func":"msg.payload = Buffer.from(msg.payload + \"\\r\");\n\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":960,"wires":[["1dfcc7e5.5d3068"]]},{"id":"1dfcc7e5.5d3068","type":"debug","z":"fb2d52d1.30eaa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":480,"y":960,"wires":[]}]

image

2 Likes

Indeed, it's working, thanks!

My error was that I was trying to do my carriage return outside of my script (inside the msg.payload) and for some reason, that didn't translate well.