Sending buffers to Serial Port Node - Error


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:

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:

[{"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.

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!


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 ?

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:

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.

I get

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.

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

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:

[{"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"}]


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.

Yes. Thanks for the help!

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