# Sending ASCII Codes thru TCP out node

**URL:** <https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088>\
**Category:** Industrial\
**Created:** [16 October 2023 18:25 UTC](https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088 "2023-10-16T18:25:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)\
**Post date:** [16 October 2023 18:25 UTC](https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088/1 "2023-10-16T18:25:51Z")

</div>

I am using a TCP out node to send data to a server in order to mimic our current PLC socket connection message structure but I am not sure how to insert ASCI codes as part of this message.

```auto
[
    {
        "id": "f3a6c6925f5bde8b",
        "type": "tcp out",
        "z": "f2ee9bee06dc25c0",
        "name": "",
        "host": "10.3.102.164",
        "port": "57200",
        "beserver": "client",
        "base64": false,
        "end": false,
        "tls": "",
        "x": 870,
        "y": 980,
        "wires": []
    },
    {
        "id": "0dbe48d8bf3570a8",
        "type": "inject",
        "z": "f2ee9bee06dc25c0",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{SOH}H 41580{STX}{ETX} {EOT}",
        "payloadType": "str",
        "x": 490,
        "y": 980,
        "wires": [
            [
                "f3a6c6925f5bde8b",
                "b2e00899a82c3129"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 October 2023 18:53 UTC](https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088/2 "2023-10-16T18:53:52Z")

</div>

Add a function node after the inject

```auto
const SOH = String.fromCharCode(1);
const STX = String.fromCharCode(2);
const ETX = String.fromCharCode(3);
msg.payload = `${SOH}H 41580${STX}HELLO${ETX}`
return msg

```

You can take this further by adding extra stuff to the msg making the function generic/dynamic e.g..

```auto
const SOH = String.fromCharCode(1);
const STX = String.fromCharCode(2);
const ETX = String.fromCharCode(3);
msg.payload = `${SOH}${msg.header}${STX}${msg.data}${ETX}`
return msg

```

Then add `header` and `data` strings to the inject node or whatever you wish.

---

<div class="post-metadata">

**Author:** ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)\
**Post date:** [16 October 2023 19:21 UTC](https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088/4 "2023-10-16T19:21:26Z")

</div>

> [@jts450](#):
>
> Awesome this should work. I am trying to insert barcode data in the message from a TCP reader. Thank you!!

Awesome this should work. I am trying to insert barcode data in the message from a TCP reader. Thank you!!

---

<div class="post-metadata">

**Author:** ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)\
**Post date:** [18 October 2023 21:50 UTC](https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088/5 "2023-10-18T21:50:49Z")

</div>

I am now able to send this Data to our WMS system but with the TCP in Node I am not receiving an ACK message from our WMS. The TCP nodes keep connecting and reconnecting like to port is shutting down and coming back up. I don't know if its an issues with our WMS or the TCP nodes in Node-Red?

```auto
[
    {
        "id": "6edd731ed9813192",
        "type": "tcp in",
        "z": "f2ee9bee06dc25c0",
        "name": "",
        "server": "client",
        "host": "10.3.102.164",
        "port": "57200",
        "datamode": "stream",
        "datatype": "utf8",
        "newline": "",
        "topic": "",
        "trim": false,
        "base64": false,
        "tls": "",
        "x": 420,
        "y": 920,
        "wires": [
            [
                "9b24893228a1dd77"
            ]
        ]
    },
    {
        "id": "9b24893228a1dd77",
        "type": "debug",
        "z": "f2ee9bee06dc25c0",
        "name": "debug 11",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 920,
        "wires": []
    },
    {
        "id": "58cde8abf74affce",
        "type": "function",
        "z": "f2ee9bee06dc25c0",
        "name": "function 3",
        "func": "const SOH = String.fromCharCode(1);\nconst STX = String.fromCharCode(2);\nconst ETX = String.fromCharCode(3);\nconst EOT = String.fromCharCode(4);\nmsg.payload = `${SOH}H 41581${STX}${ETX} ${EOT}`\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 1060,
        "wires": [
            [
                "5316df909ad45dfd",
                "6f330034d12e7f6c"
            ]
        ]
    },
    {
        "id": "92807b9f46656773",
        "type": "inject",
        "z": "f2ee9bee06dc25c0",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "header",
                "v": "HeaderTest",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{SOH}H 41580{STX}{ETX} {EOT}",
        "payloadType": "str",
        "x": 250,
        "y": 1060,
        "wires": [
            [
                "58cde8abf74affce"
            ]
        ]
    },
    {
        "id": "5316df909ad45dfd",
        "type": "debug",
        "z": "f2ee9bee06dc25c0",
        "name": "debug 17",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 1060,
        "wires": []
    },
    {
        "id": "6f330034d12e7f6c",
        "type": "tcp out",
        "z": "f2ee9bee06dc25c0",
        "name": "",
        "host": "10.3.102.164",
        "port": "57200",
        "beserver": "client",
        "base64": false,
        "end": false,
        "tls": "",
        "x": 690,
        "y": 980,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)\
**Post date:** [18 October 2023 21:54 UTC](https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088/6 "2023-10-18T21:54:02Z")

</div>

I should say I am trying to mimic a PLC socket connection so I am unsure if there is something I need to to keep the port active...

---

<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:** [1 November 2023 21:54 UTC](https://discourse.nodered.org/t/sending-ascii-codes-thru-tcp-out-node/82088/7 "2023-11-01T21:54:38Z")

</div>

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