# Data length error, expected x got y (x \> y)

**URL:** <https://discourse.nodered.org/t/data-length-error-expected-x-got-y-x-y/99153>\
**Category:** Industrial\
**Tags:** modbus\
**Created:** [24 September 2025 15:12 UTC](https://discourse.nodered.org/t/data-length-error-expected-x-got-y-x-y/99153 "2025-09-24T15:12:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BairDev](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bairdev/32/103480_2.png) [@BairDev](https://discourse.nodered.org/u/BairDev)\
**Post date:** [24 September 2025 15:12 UTC](https://discourse.nodered.org/t/data-length-error-expected-x-got-y-x-y/99153/1 "2025-09-24T15:12:25Z")

</div>

We can communicate with a device at `/dev/ttyAMA0`.

It uses ModBus RTU, 9600 baud rate.

But when I try to read data according to the documentation of the device I am getting the error:

### `"Data length error, expected 7 got 2"`

The reading configuration:

```auto
{
    'fc': 3, // Modbus function 0x03
    'unitid': 0,

    'address': 2,
    'quantity': 1
}

```

We also get a timeout error quite often. So there might be problems regarding _parity_ and _stop bits_, but I cannot see, how we configure this in [node-red-contrib-modbus](https://flows.nodered.org/node/node-red-contrib-modbus).

Any idea for the reason of this kind of problem?

---

<div class="post-metadata">

**Author:** ![Aaqu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aaqu/32/101407_2.png) [@Aaqu](https://discourse.nodered.org/u/Aaqu)\
**Post date:** [24 September 2025 17:06 UTC](https://discourse.nodered.org/t/data-length-error-expected-x-got-y-x-y/99153/2 "2025-09-24T17:06:20Z")

</div>

Can you send part of the flow? Tell me what device it is.  
I think I once had a case where the device responded to an even number in quantity.

---

<div class="post-metadata">

**Author:** ![BairDev](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bairdev/32/103480_2.png) [@BairDev](https://discourse.nodered.org/u/BairDev)\
**Post date:** [25 September 2025 07:26 UTC](https://discourse.nodered.org/t/data-length-error-expected-x-got-y-x-y/99153/3 "2025-09-25T07:26:42Z")

</div>

### I've figured how to set parity and the number of _data bits_ etc

This can be done by selecting _Serial Expert_ for the modbus server.

I think the problem could also be caused by missed termination in the RS485 network, because no matter what I am trying with `baud rate`, `parity`, `data bits` etc., I am getting errors only (`data length error` **or** timeout). So we will check the hardware configuration there, too.

Here is the flow, but

```auto
[
    {
        "id": "1d730243db9feb8a",
        "type": "tab",
        "label": "ModBus Seriell ClampOn ",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "a4c9a2f40bc6910c",
        "type": "modbus-flex-getter",
        "z": "1d730243db9feb8a",
        "name": "Serial ModBus ClampOn",
        "showStatusActivities": true,
        "showErrors": true,
        "showWarnings": false,
        "logIOActivities": false,
        "server": "9918af96579ce096",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": true,
        "delayOnStart": false,
        "enableDeformedMessages": false,
        "startDelayTime": "2",
        "x": 570,
        "y": 180,
        "wires": [
            [
                "1e69851eced5d421"
            ],
            [
                "699db3ec86531f6b"
            ]
        ]
    },
    {
        "id": "7bb0e6a2935402b5",
        "type": "inject",
        "z": "1d730243db9feb8a",
        "name": "trigger",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 110,
        "y": 100,
        "wires": [
            [
                "cdacefc17ac2b270"
            ]
        ]
    },
    {
        "id": "cdacefc17ac2b270",
        "type": "function",
        "z": "1d730243db9feb8a",
        "name": "FC ??? -- 4 517 [6]",
        "func": "\nmsg.payload = { \n // value is true WHY ????\n // value: msg.payload,\n // https://blog.softwaretoolbox.com/opc-modbus-function-codes\n 'fc': 3,\n 'unitid': 0,\n\n 'address': 1,\n 'quantity': 1\n};\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 330,
        "y": 180,
        "wires": [
            [
                "a4c9a2f40bc6910c"
            ]
        ]
    },
    {
        "id": "1e69851eced5d421",
        "type": "debug",
        "z": "1d730243db9feb8a",
        "name": "debug 4",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 140,
        "wires": []
    },
    {
        "id": "699db3ec86531f6b",
        "type": "debug",
        "z": "1d730243db9feb8a",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 220,
        "wires": []
    },
    {
        "id": "9918af96579ce096",
        "type": "modbus-client",
        "name": "",
        "clienttype": "serial",
        "bufferCommands": true,
        "stateLogEnabled": true,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "127.0.0.1",
        "tcpPort": 502,
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyAMA0",
        "serialType": "RTU",
        "serialBaudrate": "9600",
        "serialDatabits": "5",
        "serialStopbits": 1,
        "serialParity": "none",
        "serialConnectionDelay": 100,
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": 0,
        "commandDelay": 0,
        "clientTimeout": 2000,
        "reconnectOnTimeout": false,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": false,
        "showErrors": true,
        "showWarnings": true,
        "showLogs": true
    },
    {
        "id": "2d201daaac4afbbb",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-contrib-modbus": "5.44.1"
        }
    }
]

```

#### But I cannot change the value for this configuration field: `"serialAsciiResponseStartDelimiter": "0x3A"`, right?

---

<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:** [24 November 2025 07:27 UTC](https://discourse.nodered.org/t/data-length-error-expected-x-got-y-x-y/99153/4 "2025-11-24T07:27:07Z")

</div>

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