# How to send data with null character to a Serial port?

**URL:** https://discourse.nodered.org/t/how-to-send-data-with-null-character-to-a-serial-port/17986
**Category:** General
**Created:** [15 November 2019 03:03 UTC](https://discourse.nodered.org/t/how-to-send-data-with-null-character-to-a-serial-port/17986 "2019-11-15T03:03:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![iono](https://avatars.discourse-cdn.com/v4/letter/i/65b543/32.png) [@iono](https://discourse.nodered.org/u/iono)
#### Post date: [15 November 2019 03:03 UTC](https://discourse.nodered.org/t/how-to-send-data-with-null-character-to-a-serial-port/17986/1 "2019-11-15T03:03:53Z")

</div>

Hi, I am new to Node-Red and is trying things around.

I have a ToF sensor that will send distance data only if it is activated by sending a specific set of bytes to it. On node.js, this is how it is done:

> function activateBuffer(){  
> var arr = [];  
> arr.push(0);  
> arr.push(17);  
> arr.push(1);  
> arr.push(69);  
> return new Buffer(arr);  
> }
> 
> port.on('open', function() {  
> port.write( activateBuffer() );  
> });

On Node-Red, I have been trying to play around with sending data using INJECT, but I am not sure how can I type in a null character in the INJECT's Buffer payload in this case.

The numbers above could be changed to hexadecimal as 00 11 01 45, so in INJECT, I need to provide ASCII characters to match that. Something like "(null)E" in the buffer editor to get 00 11 01 45, but when I copy and paste, I only got "E", and no null character. So what can be done here?

PS. also, note that when I edit this, I could see the hex 11 and 01 as rectangular boxes, but when I posted it, those characters are invisible in the post somehow...

Alternatively, I have also tried the FUNCTION, and have INJECT invoke the FUNCTION which contains this code:

> var arr = [];  
> arr.push(0);  
> arr.push(17);  
> arr.push(1);  
> arr.push(69);  
> return new Buffer(arr);

I then connect INJECT to FUNCTION to DEBUG, but when I deploy and activate INJECT, I got the following error:

"Function tried to send a message of type Buffer"

So in this case, how can I do this?

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [15 November 2019 03:54 UTC](https://discourse.nodered.org/t/how-to-send-data-with-null-character-to-a-serial-port/17986/2 "2019-11-15T03:54:01Z")

</div>

> [@iono](#):
>
> I then connect INJECT to FUNCTION to DEBUG, but when I deploy and activate INJECT, I got the following error:

Try to configure the inject node as shown below.

![r-001](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b9c3ad03c1392d863ebeaf6267c161340f10174b.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [15 November 2019 07:21 UTC](https://discourse.nodered.org/t/how-to-send-data-with-null-character-to-a-serial-port/17986/3 "2019-11-15T07:21:30Z")

</div>

Just so you know, the reason for the error is that you must always return a message not just avalue or buffer. Setting `msg.psyload` to your buffer would have fixed that.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [15 November 2019 12:03 UTC](https://discourse.nodered.org/t/how-to-send-data-with-null-character-to-a-serial-port/17986/4 "2019-11-15T12:03:33Z")

</div>

> [@Colin](#):
>
> Setting `msg.`psy`load` to your buffer would have fixed that

Cool, does that send the data straight into your brain! 🧙🤣

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [15 November 2019 13:44 UTC](https://discourse.nodered.org/t/how-to-send-data-with-null-character-to-a-serial-port/17986/5 "2019-11-15T13:44:54Z")

</div>

Sadly it seems I can't even reliably get messages from by brain to my fingers never mind node-red to my brain.
