# Sending buffers to Serial Port Node - Error

**URL:** <https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967>\
**Category:** General\
**Created:** [16 September 2020 17:26 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967 "2020-09-16T17:26:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveDave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davedave/32/29000_2.png) [@DaveDave](https://discourse.nodered.org/u/DaveDave)\
**Post date:** [16 September 2020 17:26 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/1 "2020-09-16T17:26:48Z")

</div>

Hi,

I've been working on this for a while now with no success, so it's time to ask for some help.

I'm using Node-Red on a RPI with node-red-node-serialport to communicate with a serial device that accepts ASCII commands. Mostly this is working, however, I need to send an escape character: CTRL-C to switch operating modes on the device. Sending as a string does not work, so I am attempting to send this as a buffer containing 0x03. I am expecting this should send to the device, but I am getting an error from the serial port node:

```auto
9/16/2020, 9:47:29 AMnode: 6bf07264.52d10cmsg.payload : buffer[1]
[3]
9/16/2020, 9:47:29 AMnode: 254eb66d.fa32a2
msg : error
"TypeError [ERR_INVALID_ARG_TYPE]: The "list[1]" argument must be one of type Array, Buffer, or Uint8Array. Received type string"

```

This is the flow I'm using to test this:

```auto
[{"id":"6bf07264.52d10c","type":"debug","z":"32cf40d4.4b2a7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1450,"y":700,"wires":[]},{"id":"417b8d50.e8b3f4","type":"inject","z":"32cf40d4.4b2a7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[3]","payloadType":"bin","x":1250,"y":660,"wires":[["6bf07264.52d10c","254eb66d.fa32a2"]]},{"id":"254eb66d.fa32a2","type":"serial out","z":"32cf40d4.4b2a7","name":"","serial":"b2472a99.985c7","x":1450,"y":640,"wires":[]},{"id":"b2472a99.985c7","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"high","rts":"high","cts":"high","dsr":"high","newline":"\\n","bin":"bin","out":"char","addchar":"","responsetimeout":"10000"}]

```

I found this previous thread with the same issue, but the resolution of clearing the "Add character to output messages" value in the serial settings doesn't help. I have tried with this field empty and with \r.

> [@Send Buffer over usb Serial Node](https://discourse.nodered.org/t/send-buffer-over-usb-serial-node/16494/9):
>
> Thanks for mentioning - pushed a fix so shouldn't happen again.

The problem seems to be the serial module to not recognize the buffer coming into it, and sees it as a string.

Even if i sort out the buffer - serial issue, I'm not sure if this will solve my issue of sending a CTRL-C, but I can't get past it.

Any help is most appreciated!

Thanks,  
D

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 September 2020 19:12 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/2 "2020-09-16T19:12:05Z")

</div>

That would seem to be right and working for me (though I don't have a specific device to catch the output) - what is the AMnode above ? Is that is some other log not Node-RED ?

---

<div class="post-metadata">

**Author:** ![DaveDave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davedave/32/29000_2.png) [@DaveDave](https://discourse.nodered.org/u/DaveDave)\
**Post date:** [16 September 2020 19:29 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/3 "2020-09-16T19:29:33Z")

</div>

Hmm. Do you not get the error from the serial out node as shown above? I don't believe the node is even accepting the input in my case.

"AMnode" should be:

```auto
9/16/2020, 9:47:29 AM node: 6bf07264.52d10 msg.payload : buffer[1]

```

It must have removed the spaces when I pasted the error from the debug console.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 September 2020 19:40 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/4 "2020-09-16T19:40:35Z")

</div>

I get

```auto
16 Sep 20:37:44 - [info] Started flows
16 Sep 20:37:44 - [info] serial port /dev/ttyUSB0 opened at 9600 baud 8N1

```

and nothing else.

I don't have an AM node as you never shared it. The format of the log is not the same so what process is that ? If anything that looks like an error from whatever that node is not the serialport.

---

<div class="post-metadata">

**Author:** ![DaveDave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davedave/32/29000_2.png) [@DaveDave](https://discourse.nodered.org/u/DaveDave)\
**Post date:** [16 September 2020 20:18 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/5 "2020-09-16T20:18:05Z")

</div>

Hi Sorry for the confusion, AM is part of the timestamp from the debug window copy:

```auto
9:47:29 AM

```

I think I've made some progress in identifying the issue:

I started from scratch and deleted all my serial configurations. I can get it to work if i have only one configuration profile, there is no entry in "Add character to output messages" and I send a buffer to the serial node.

In my application I need to normally send string commands to the serial port and I do require the "/r" to be set in the "Add character to output messages" field. However, if there is anything in this field, then it breaks the buffer input to the serial node. As a workaround I tried adding a second serial port config using the same device /dev/ttyUSB0 but with the "Add character to output messages" field empty. I set a new serial output node using this alternate port configuration, but it does not seem to work - I get the error as above.

So, the solution seems to be to use a single serial configuration profile, but to not use the "Add character to output messages" feature. I then need to add the \r to each string going into the serial node. Maybe there is a more efficient way to do this, but this will get things working for me:

```auto
[{"id":"3140e82f.8a3b1","type":"serial out","z":"4fc53d7c.a61a0c","name":"Serial Out","serial":"d300c81d.796f18","x":1220,"y":400,"wires":[]},{"id":"a0f2f643.ae0bb8","type":"inject","z":"4fc53d7c.a61a0c","name":"0x03 ETX Code","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"0x03\"]","payloadType":"bin","x":620,"y":400,"wires":[["3140e82f.8a3b1","58087e57.c43378"]]},{"id":"1a20496f.03c93f","type":"inject","z":"4fc53d7c.a61a0c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"command","payloadType":"str","x":620,"y":520,"wires":[["383f0a12.36e8ce"]]},{"id":"58087e57.c43378","type":"debug","z":"4fc53d7c.a61a0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":460,"wires":[]},{"id":"383f0a12.36e8ce","type":"function","z":"4fc53d7c.a61a0c","name":"Append \\r return to strings","func":"msg.payload = msg.payload +\"\\r\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":840,"y":520,"wires":[["58087e57.c43378","3140e82f.8a3b1"]]},{"id":"d300c81d.796f18","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

```

Thanks!

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 September 2020 20:41 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/6 "2020-09-16T20:41:56Z")

</div>

Yes, you can only really have one config per physical port. So yes best option is to just add \r to any strings using a simple function node to concatenate it on the end for those that need it.

---

<div class="post-metadata">

**Author:** ![DaveDave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davedave/32/29000_2.png) [@DaveDave](https://discourse.nodered.org/u/DaveDave)\
**Post date:** [16 September 2020 21:15 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/7 "2020-09-16T21:15:16Z")

</div>

Yes. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 September 2020 21:15 UTC](https://discourse.nodered.org/t/sending-buffers-to-serial-port-node-error/32967/8 "2020-09-30T21:15:30Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
