Sending ASCII Codes thru TCP out node

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.

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

Add a function node after the inject

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..

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.

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

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?

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

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...

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