# CRC 16XMODEM node

**URL:** <https://discourse.nodered.org/t/crc-16xmodem-node/94516>\
**Category:** General\
**Created:** [10 January 2025 19:12 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516 "2025-01-10T19:12:38Z")\
**Posts on this page:** 9\
**Page:** 2

<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:** [18 January 2025 13:51 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/21 "2025-01-18T13:51:28Z")

</div>

> [@pin32](#):
>
> if I transmit the command as text it works

I don't know what this means. You have provided no context.

As for why the serial node might not work, it is possible due to setup. For example, you may be appending a carriage return or not appending a carriage return or whatever your protocol needs. You have not provided this information.

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [18 January 2025 14:07 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/22 "2025-01-18T14:07:53Z")

</div>

the serial works correctly and sending commands in text format works and returns the response you expect. some commands work without crc others require the crc but the serial configuration works properly, the wrap character is included in the serial node configuration.

 ![Schermata del 2025-01-18 15-07-33](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd22e71dac18dc67973e08036e49ce417558a6f6.png)

---

<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:** [18 January 2025 14:11 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/23 "2025-01-18T14:11:30Z")

</div>

Given the lack of detailed protocol information, I can only guess.

Perhaps you need to send the data as bytes (AKA a buffer) because sending `51550494753b7a9` is a string of HEXADECIMAL

Try setting the payload (the one that goes to the serial node) so that is sends a buffer.

e.g...

Function Node "Hex String to Buffer"

```auto
msg.payload = Buffer.from(msg.payload, 'hex')
return msg

```

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [18 January 2025 14:11 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/24 "2025-01-18T14:11:45Z")

</div>

![Schermata del 2025-01-18 15-10-50](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab8cb87615fe56f902406285046b67f3943da7a0.png)

This command requires the crc

---

<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:** [18 January 2025 14:15 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/25 "2025-01-18T14:15:46Z")

</div>

Alternatively, convert the HEX string into a regular string

```auto
msg.payload = Buffer.from(msg.payload, 'hex').toString()
return msg

```

e.g:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f80e5eac090151d2e7b433f48c6a5e91d93aeb0.png)

`51550494753b7a9` becomes → `'QU\x04�u;z'`

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [18 January 2025 18:47 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/26 "2025-01-18T18:47:08Z")

</div>

in fact you guessed right! if I change in buffer it also works by sending the commands in hex

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [18 January 2025 19:58 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/27 "2025-01-18T19:58:31Z")

</div>

```auto
[
    {
        "id": "edf507bc4f9d5dec",
        "type": "serial out",
        "z": "2e439fa544a77ab5",
        "name": "VMIII-TX",
        "serial": "831becf24befe30b",
        "x": 860,
        "y": 1280,
        "wires": []
    },
    {
        "id": "e2beeb574d982801",
        "type": "inject",
        "z": "2e439fa544a77ab5",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "calculate",
        "payload": "5043565635352e36",
        "payloadType": "str",
        "x": 180,
        "y": 1280,
        "wires": [
            [
                "6154059a3dde693d",
                "642ae841afbc5196"
            ]
        ]
    },
    {
        "id": "a3644ecebee6a043",
        "type": "function",
        "z": "2e439fa544a77ab5",
        "name": "buffer",
        "func": "msg.payload = Buffer.from(msg.payload, 'hex')\nreturn msg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 610,
        "y": 1280,
        "wires": [
            [
                "edf507bc4f9d5dec",
                "ec608cbea3497578"
            ]
        ]
    },
    {
        "id": "6154059a3dde693d",
        "type": "function",
        "z": "2e439fa544a77ab5",
        "name": "xmodem crc",
        "func": "const { crc16 } = easyCrc;\nmsg.inputData = msg.payload;\nmsg.buffer = Buffer.from(msg.payload, 'hex');\nmsg.crcDecimal = crc16('XMODEM', msg.buffer);\nmsg.crcHex = msg.crcDecimal.toString(16)\nmsg.payload = `${msg.inputData}${msg.crcHex}`\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "easyCrc",
                "module": "easy-crc"
            }
        ],
        "x": 430,
        "y": 1280,
        "wires": [
            [
                "a3644ecebee6a043",
                "7914e91b46a9971c"
            ]
        ]
    },
    {
        "id": "7914e91b46a9971c",
        "type": "debug",
        "z": "2e439fa544a77ab5",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 1320,
        "wires": []
    },
    {
        "id": "ec608cbea3497578",
        "type": "debug",
        "z": "2e439fa544a77ab5",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 1320,
        "wires": []
    },
    {
        "id": "642ae841afbc5196",
        "type": "debug",
        "z": "2e439fa544a77ab5",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 420,
        "y": 1320,
        "wires": []
    },
    {
        "id": "31e7bfd73af61468",
        "type": "inject",
        "z": "2e439fa544a77ab5",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "calculate",
        "payload": "PCVV55.4",
        "payloadType": "str",
        "x": 150,
        "y": 1340,
        "wires": [
            []
        ]
    },
    {
        "id": "831becf24befe30b",
        "type": "serial-port",
        "name": "",
        "serialport": "/dev/ttyACM0",
        "serialbaud": "2400",
        "databits": 8,
        "parity": "none",
        "stopbits": 1,
        "waitfor": "(",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\r",
        "bin": "false",
        "out": "char",
        "addchar": "\\r",
        "responsetimeout": 10000
    }
]

```

We are almost there, the merits are certainly yours, in my small I have however learned something more and thank you.  
now works properly by sending a string containing hex values. a last step would be to send the commands in text format and turn them into hex string to give to crc and the game is done.  
this because the crc node results only in hex, for what I understood, otherwise it would be better to do the crc directly with text and then make a buffer and send to the serial. but I have no idea if it’s feasible.  
Thank you for your patience in supporting beginners like me!

---

<div class="post-metadata">

**Author:** ![pin32](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pin32](https://discourse.nodered.org/u/pin32)\
**Post date:** [19 January 2025 07:03 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/28 "2025-01-19T07:03:22Z")

</div>

```auto

[
    {
        "id": "007424808c9b6283",
        "type": "mqtt in",
        "z": "2e439fa544a77ab5",
        "name": "COMMAND/RX",
        "topic": "DATI FOTOVOLTAICO/NODE-RED/INVERTER_VOLTRONIC/COMMAND/TX",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "e276a877253691df",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 120,
        "y": 1060,
        "wires": [
            [
                "289e35eef21e61a0",
                "7290101b4768b299"
            ]
        ]
    },
    {
        "id": "a409a644c23f12d9",
        "type": "cyclic counter",
        "z": "2e439fa544a77ab5",
        "name": "cyclic counter",
        "maxCount": "6",
        "timeoutDuration": 0,
        "timeoutUnit": "ms",
        "outputProperty": "payload",
        "x": 320,
        "y": 980,
        "wires": [
            [
                "9fbe16961891930f"
            ]
        ]
    },
    {
        "id": "3a9e655f2b972f20",
        "type": "inject",
        "z": "2e439fa544a77ab5",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "2",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 980,
        "wires": [
            [
                "a409a644c23f12d9"
            ]
        ]
    },
    {
        "id": "9fbe16961891930f",
        "type": "change",
        "z": "2e439fa544a77ab5",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "num",
                "to": "QPIGS",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "2",
                "fromt": "num",
                "to": "QMOD",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "3",
                "fromt": "num",
                "to": "QPIGS",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "4",
                "fromt": "num",
                "to": "QPIWS",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "5",
                "fromt": "num",
                "to": "QPIGS",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "6",
                "fromt": "num",
                "to": "QPIRI",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 520,
        "y": 980,
        "wires": [
            [
                "d49e167477b1d0b1"
            ]
        ]
    },
    {
        "id": "289e35eef21e61a0",
        "type": "trigger",
        "z": "2e439fa544a77ab5",
        "name": "",
        "op1": "close",
        "op2": "open",
        "op1type": "str",
        "op2type": "str",
        "duration": "10",
        "extend": true,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 330,
        "y": 1060,
        "wires": [
            [
                "67211f5b338da45d"
            ]
        ]
    },
    {
        "id": "67211f5b338da45d",
        "type": "change",
        "z": "2e439fa544a77ab5",
        "name": "move",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "control",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 1060,
        "wires": [
            [
                "d49e167477b1d0b1"
            ]
        ]
    },
    {
        "id": "d49e167477b1d0b1",
        "type": "gate",
        "z": "2e439fa544a77ab5",
        "name": "demo gate",
        "controlTopic": "control",
        "defaultState": "open",
        "openCmd": "open",
        "closeCmd": "close",
        "toggleCmd": "toggle",
        "defaultCmd": "default",
        "statusCmd": "status",
        "persist": false,
        "x": 730,
        "y": 1060,
        "wires": [
            [
                "f68aa936bb103d57"
            ]
        ]
    },
    {
        "id": "f68aa936bb103d57",
        "type": "switch",
        "z": "2e439fa544a77ab5",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "close",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "open",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 890,
        "y": 1060,
        "wires": [
            [],
            [],
            [
                "a99ad4b6bb706893"
            ]
        ]
    },
    {
        "id": "7290101b4768b299",
        "type": "delay",
        "z": "2e439fa544a77ab5",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 320,
        "y": 1120,
        "wires": [
            [
                "a99ad4b6bb706893"
            ]
        ]
    },
    {
        "id": "edf507bc4f9d5dec",
        "type": "serial out",
        "z": "2e439fa544a77ab5",
        "name": "VMIII-TX",
        "serial": "831becf24befe30b",
        "x": 1320,
        "y": 1120,
        "wires": []
    },
    {
        "id": "3f6be7eed08ff7d8",
        "type": "debug",
        "z": "2e439fa544a77ab5",
        "name": "TX Seriale",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1330,
        "y": 1180,
        "wires": []
    },
    {
        "id": "a99ad4b6bb706893",
        "type": "function",
        "z": "2e439fa544a77ab5",
        "name": "str>hex/crc/buffer",
        "func": "msg.payload = Buffer.from(msg.payload, 'utf-8').toString('hex');\n\nconst { crc16 } = easyCrc;\nmsg.inputData = msg.payload;\nmsg.buffer = Buffer.from(msg.payload, 'hex');\nmsg.crcDecimal = crc16('XMODEM', msg.buffer);\nmsg.crcHex = msg.crcDecimal.toString(16)\nmsg.payload = `${msg.inputData}${msg.crcHex}`\n\nmsg.payload = Buffer.from(msg.payload, 'hex')\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "easyCrc",
                "module": "easy-crc"
            }
        ],
        "x": 1110,
        "y": 1120,
        "wires": [
            [
                "edf507bc4f9d5dec",
                "3f6be7eed08ff7d8"
            ]
        ]
    },
    {
        "id": "e276a877253691df",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.1.99",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "5",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "831becf24befe30b",
        "type": "serial-port",
        "name": "",
        "serialport": "/dev/ttyACM0",
        "serialbaud": "2400",
        "databits": 8,
        "parity": "none",
        "stopbits": 1,
        "waitfor": "(",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\r",
        "bin": "false",
        "out": "char",
        "addchar": "\\r",
        "responsetimeout": 10000
    }
]

```

Good morning.  
I have given a fix to the stream that I built with your help!  
I publish in its completeness with the hope that it can be improved and also in the interest of others looking for a solution... as happened in my case.  
Thanks again  
[flussoCRC .json](https://discourse.nodered.org/uploads/short-url/ui5ApfBLH29io36u2SGH63ycPQ8.json) (8.9 KB)

---

<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:** [19 April 2025 07:03 UTC](https://discourse.nodered.org/t/crc-16xmodem-node/94516/29 "2025-04-19T07:03:44Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/crc-16xmodem-node/94516.md?page=1)
