ModBus TCP Read 64-bit registers

Dear community members, I am trying to read some parameters from a Schneider Electric Smartlink SI D Power meter via Modbus TCP but I do not know how to read the Watthours, I can read the Voltage, Amperage, and Wattage, Those are of a Float32 format. The Modbus address for the Watthours is 3203 but it is an Int64 format. When I try to read it with Int32 it reads 0, When I try Int64 it gives an error.

Does someone know how to make this work?

Thanks!

Can't really help if you don't show us the code and the error other than point you to the buffer documentation...
Buffer | Node.js v21.5.0 Documentation

I understand that Int64 isn't supported native by node-red, but is there an way to make it work?

Support for reading 64bit ints from Buffers was added in Node 12 - and note the function is called readBigInt64BE not readUInt64BE.

They return a BigInt object, which has some particular behaviours you need to be aware of - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt

Did you read the link? The function you called doesn't exist.

Okay I changed it to readBigInt64BE, it gives this error now.

Have you tried searching for the meaning of that error?

Sounds to me like your Buffer isn't big enough to contain a 64 bit number.

Pass the Buffer to a Debug node and share what it shows.

Not yet :wink:

Your buffer only has 4 bytes

4 X 8 = 32 bits

Get more data from the device and try again.

how can i get more data from the device? The modbus getter node just pulls the data from the Schneider power meter. the modbus table in the manual says its an Int64 format.

no idea but have a look at the properties of the FC3 Hold Reg Read node called WattHours...
image

Isnt there a length or size or count property?

If the length is current 2 (i.e. 16bit WDs) then I'd guess double it to 4.

If its 4 (i.e. bytes) then double that to 8

Post a screen shot of its settings if you arent sure.

The field quantity was set at 2, I changed it to 4 it then gave this error. When I double it to 8 is gives the same error.

Thanks for your help btw!

I'm pretty sure that is not a JS or NODE error (i.e. looks like a user coding error)

Can you share your flow?

Ps, buffer size now looks correct.

The reading of the 64bit Int is working. The error is now that a later part of your flow cannot handle the BigInt object type that has been returned by redBigInt64BE.

AS I said earlier, the BigInt object has some particular behaviours that will affect what you can do with it. You cannot treat it like just any other number.

What do you want to do with it?

hope this works, newer shared a flow before lol :wink:

please edit that and put code between 3 back ticks (it is unusable in current format)

```
like this
```

[
    {
        "id": "e905007d.6be7b",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "ddb0454d.5233b8",
        "type": "modbus-getter",
        "z": "e905007d.6be7b",
        "name": "FC 3 [150] (3027) Voltage",
        "showStatusActivities": false,
        "showErrors": false,
        "logIOActivities": false,
        "unitid": "150",
        "dataType": "HoldingRegister",
        "adr": "3027",
        "quantity": "2",
        "server": "ef18b8d5.36cf58",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "x": 340,
        "y": 80,
        "wires": [
            [],
            [
                "f4d32a73.d52f98"
            ]
        ]
    },
    {
        "id": "d960f91.4d22d08",
        "type": "modbus-getter",
        "z": "e905007d.6be7b",
        "name": "FC 3 [150] (3059) Wattage",
        "showStatusActivities": false,
        "showErrors": false,
        "logIOActivities": false,
        "unitid": "150",
        "dataType": "HoldingRegister",
        "adr": "3059",
        "quantity": "2",
        "server": "ef18b8d5.36cf58",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "x": 340,
        "y": 240,
        "wires": [
            [],
            [
                "c0203137.bf881"
            ]
        ]
    },
    {
        "id": "d641fe0c.f9778",
        "type": "modbus-getter",
        "z": "e905007d.6be7b",
        "name": "FC 3 [150] (2999) Amperage",
        "showStatusActivities": false,
        "showErrors": false,
        "logIOActivities": false,
        "unitid": "150",
        "dataType": "HoldingRegister",
        "adr": "2999",
        "quantity": "2",
        "server": "ef18b8d5.36cf58",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "x": 340,
        "y": 160,
        "wires": [
            [],
            [
                "af4ce282.20cc5"
            ]
        ]
    },
    {
        "id": "1b77b382.24e7cc",
        "type": "inject",
        "z": "e905007d.6be7b",
        "name": "",
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "repeat": "60",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 90,
        "y": 200,
        "wires": [
            [
                "ddb0454d.5233b8",
                "d641fe0c.f9778",
                "d960f91.4d22d08",
                "9e28e6fd.27fa08"
            ]
        ]
    },
    {
        "id": "f4d32a73.d52f98",
        "type": "function",
        "z": "e905007d.6be7b",
        "name": "ReadFloat 32",
        "func": "const buf = Buffer.from(msg.payload.buffer);\nconst value = buf.readFloatBE();\nmsg.payload = {\"Voltage\": value};\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 580,
        "y": 80,
        "wires": [
            [
                "206bb69e.ee399a"
            ]
        ]
    },
    {
        "id": "af4ce282.20cc5",
        "type": "function",
        "z": "e905007d.6be7b",
        "name": "ReadFloat 32",
        "func": "const buf = Buffer.from(msg.payload.buffer);\nconst value = buf.readFloatBE();\nmsg.payload = {\"Amperage\": value};\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 580,
        "y": 160,
        "wires": [
            [
                "206bb69e.ee399a"
            ]
        ]
    },
    {
        "id": "c0203137.bf881",
        "type": "function",
        "z": "e905007d.6be7b",
        "name": "ReadFloat 32",
        "func": "const buf = Buffer.from(msg.payload.buffer);\nconst value = buf.readFloatBE();\nmsg.payload = {\"Wattage\": value};\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 580,
        "y": 240,
        "wires": [
            [
                "206bb69e.ee399a"
            ]
        ]
    },
    {
        "id": "206bb69e.ee399a",
        "type": "join",
        "z": "e905007d.6be7b",
        "name": "",
        "mode": "custom",
        "build": "merged",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "4",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 790,
        "y": 200,
        "wires": [
            [
                "4d324b86.d31414"
            ]
        ]
    },
    {
        "id": "9e28e6fd.27fa08",
        "type": "modbus-getter",
        "z": "e905007d.6be7b",
        "name": "FC 3 [150] (3203) Watthours",
        "showStatusActivities": false,
        "showErrors": false,
        "logIOActivities": false,
        "unitid": "150",
        "dataType": "HoldingRegister",
        "adr": "3203",
        "quantity": "4",
        "server": "ef18b8d5.36cf58",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "x": 340,
        "y": 320,
        "wires": [
            [],
            [
                "100ac95d.8381a7",
                "d7e23e2d.658f4"
            ]
        ]
    },
    {
        "id": "100ac95d.8381a7",
        "type": "function",
        "z": "e905007d.6be7b",
        "name": "ReadInt 64",
        "func": "const buf = Buffer.from(msg.payload.buffer);\nconst value = buf.readBigInt64BE()\nmsg.payload = {\"Energy\": value};\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 590,
        "y": 320,
        "wires": [
            [
                "206bb69e.ee399a"
            ]
        ]
    },
    {
        "id": "4d324b86.d31414",
        "type": "debug",
        "z": "e905007d.6be7b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 950,
        "y": 200,
        "wires": []
    },
    {
        "id": "d7e23e2d.658f4",
        "type": "debug",
        "z": "e905007d.6be7b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 580,
        "y": 380,
        "wires": []
    },
    {
        "id": "ef18b8d5.36cf58",
        "type": "modbus-client",
        "z": "",
        "name": "Smartlink SI D",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "tcpHost": "192.168.1.24",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "unit_id": 1,
        "commandDelay": 20,
        "clientTimeout": 1000,
        "reconnectOnTimeout": false,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": false
    }
]

what version of nodejs are you using?

at a command line terminal, enter node -v

i'm using version v12.14.1

~Ah, so the join node or the http looks like its not liking the bigint?~

EDIT no - its part in the function