TCP Output Node: Needed Clarification; Please Help

Dear Sirs:
(Windows 10 Node Red install.)

Using a Cognex barcode reader/scanner. I need to communicate from Node-Red.

The TCP Input node responds well from the scanner input and Hyperterminal input as well.

I need help. I have spent a good bit of time trying to output text string to the TCP Output node to send data to a scanner. However I cannot send it commands. It simlply does not respond. I tried monitoring the output by connecting to Hyperterminal. I cannot get that to respond either. I can use Hyperterminal to send the reader/scanner commands and it works quite well.

Please help.

What is the text string you are trying to send?
What is the flow you have tried?

I was trying to find help online and I just now stumbled on this post from Nick O'Leary from 11/15/15

"The inject node does handle escape sequences like \n - it treats them as literal strings.
For now, use a Function node after your Inject node to append the newline:
msg.payload = msg.payload + '\n';
return msg;

I am sending it "||>SET SYMBOL.C128 OFF" and I had on the end and in another inject node as a trial "\r\n".
The problem is that as Nick put it. "The inject node does handle escape sequences like \n". I put the string with escapes in the Change node as well without any good result.

Node-Red Developers, Please fix the TCP Output Node such that it fills in your escape characters or you can include them in your text.


How is the tcp node node going to know if you want to send the actual character \ followed by n ? rather than \n ? It expects binary type payloads anyway so it will send whatever it is given.

PS you may want to use the tcp-request node if you want to get answers back from your device.

I did use the "TCP Request" node. I sent the command string with the command text and then a separate string with the control characters, and many other combinations. I still got nothing from the output of "TCP Request".

I was trying to get feedback from the request as to what the problem was. I used wireshark to look at the data I went around that for a bit. I could not get hyperterminal to work so it wasn't something which I could see that my terminating characters were there or not. Finally I found a forum on Google where Nick was discussing the same problem. Light-bulb moment !

My request is very simple, but perhaps not the solution. Typically, and in this situation, you need to send a string command, let's say. The command in a TCP Output in Text mode vs. Binary Mode and can be a checkbox or switch setting... Also, you can possibly include prefix/suffix for your messages. This is where you would fill in the control characters, or possibly even select them from a dropdown box. This way you just send the text values and the TCP Output could.. not saying should... address the issue of non-printable control characters within the context of your send command. ('STX'msg.payload'ETX' for example) You can do this as a rule in most terminal emulation programs. Hyperterminal, for example.

Or, perhaps to address a more complete info tab just include the fact that if this is not working for any reason, just take a look to see that you have treated the text control characters correctly as the inject or just putting control characters in the msg.payload will treat them as only text characters. And a quick blurb about the simple line of code in the function to resolve that... or both. It's just a suggestion.

All of this is already possible with the inject node, change node and function node. Would seem redundant to add another way...

1 Like

I do have some sympathy though. For software folk they kind of expect \n to represent the escaped version or the newline char - whereas hardware folk (closer to the wires) expect every character to be significant. But maybe we can add some more doc/info to things like the tcp node to make it more clear.

Or indeed maybe a string to buffer parser node that does handle \r\n and/or STX/ETX type syntax and vice-versa


Over on this discussion thread, I was just lamenting that fact that I couldn't find a way to convert an incoming buffer (containing a json string) to an actual javascript string -- short of using a function node to invoke the toString() method...

+1 Sounds like that would be useful for me as well.

I'm now having difficulty in finding the values for these escape characters
\e .. does not look like it's the character for "ESCAPE"
I also tried the values \x1B and it looks like that does not work in the "String" Node, but \r\n works great.

Can you refer me to a list of codes that work in Node-Red? Or do I just need to use a Java Script function to do the rest of my ASCII conversion using the Hexidecimal \x?? formats?


Hmm, not sure what you mean by "String" node -- but nodejs itself seems to handle the \x1b conversion from string to buffer just fine:

> new Buffer("\r\n\x1b")
<Buffer 0d 0a 1b>

The \e is just treated as a lowercase letter, since it's not valid syntax. Check out this W3Schools page for a list of the valid character escapes in Javascript.

I'm trying to talk to a printer via the TCP. I think I have the correct information to open and send the commnds, but I'm not quite getting how I can then listen to the reply and see it's response back to the connection.

Can you please help?

I think I have it. I used the TCP Request Node instead of the Output Node and it gives the reply in ASCII Decimal format. I used the String Node, "toString" to convert the ASCII Decimal to string for the Debug node.

Thanks in advance !.

The node selector on the left of the Node-Red editor. Under the topic category "Function" down under the "S's"... "string" node. It has string functions... Perhaps I may have downloaded it separately...


1 Like

@hp_apcc You probably already know this :slightly_smiling_face:, but under the Manage palette menu, the Nodes pane will give you a list of all the npm packages you have downloaded. The > switch will show the nodes included in each package. This makes it easy to distinguish NR "core" nodes from contributed ones.

Hi there, i'am trying to do the same thing and send command to the printer. Have you figure out a solution ? And thanks in advance.

As it turns out its fairly simple. The solution is as follows.

You need to be careful of escape characters where you include them in your string to your printer.
If you have anything specific, please share it.