npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ismaillowkey/plc-value-converter

v0.5.2

Published

Node-RED node to convert an array of Modbus registers to specific value types

Readme

Node-RED Contrib PLC Value Converter

English | Bahasa Indonesia


English

A Node-RED custom node designed to seamlessly convert Modbus 16-bit register arrays into various human-readable data types (Float, Integer, String) and vice versa.

[!NOTE] This node is designed as an add-on / companion to be used alongside the node-red-contrib-modbus library.

Nodes Included:

  1. PLC Value Converter: Reads an array of 16-bit registers (e.g., from a Modbus Read node) and converts them into numeric values (Float, Int, Uint). Supports optional decimal rounding options for float values and automatically hides the Endianness dropdown for 16-bit types.
  2. PLC Multi Value Converter: Converts a single large array of Modbus registers into an array of multiple numeric values. Supports dynamic length configuration, dynamic UI visibility, and decimal rounding.
  3. Single Divide: Scales down/divides a single numeric value in msg.payload by a configured divisor (e.g., divide by 10).
  4. Multi Divide: Scales down/divides each element in an array of numbers in msg.payload by a configured divisor (e.g., divide by 10).
  5. PLC Write Converter: Converts numeric values back into an array of 16-bit registers to be written into a PLC (e.g., via a Modbus Write node).
  6. String Converter: Reads an array of 16-bit registers and converts them into ASCII strings (supports Normal and Reverse byte ordering).
  7. Write String Converter: Converts an ASCII string into an array of 16-bit registers to be written to a PLC.
  8. Unix (s) to Date: Converts a Unix timestamp (seconds) into a date array [Year, Month, Day, Hour, Minute, Second].
  9. Unix (ms) to Date: Converts a Unix timestamp (milliseconds) into a date array [Year, Month, Day, Hour, Minute, Second, Millisecond].
  10. Date to Unix (s): Converts a date array [Year, Month, Day, Hour, Minute, Second] into a Unix timestamp (seconds).

How Many Registers (Array Length) Are Needed?

When reading or writing from Modbus, data types require different amounts of 16-bit registers:

  • Int16 / UInt16: Requires 1 register (1 array element).
  • Int32 / UInt32: Requires 2 registers (2 array elements).
  • Float32: Requires 2 registers (2 array elements).
  • Float64 (Double): Requires 4 registers (4 array elements).
  • Int64 / UInt64: Requires 4 registers (4 array elements).
  • String:
    • If 1 Word = 1 Character: Requires exactly the length of the string (e.g., 5 characters = 5 registers).
    • If 1 Word = 2 Characters: Requires half the length of the string (e.g., 10 characters = 5 registers).

Outputs

  • Output 1 (Success): Contains the successfully converted value (or array).
  • Output 2 (Error): Outputs an error message if the conversion fails (e.g., if the input array is too short for the chosen data type).

Bahasa Indonesia

Sebuah custom node Node-RED yang dirancang untuk mempermudah konversi array register 16-bit Modbus menjadi berbagai tipe data yang mudah dibaca manusia (Float, Integer, String) dan juga sebaliknya.

[!NOTE] Node ini adalah tambahan (add-on) pendamping yang dirancang khusus untuk digunakan bersama dengan library utama node-red-contrib-modbus.

Node yang Tersedia:

  1. PLC Value Converter: Membaca array dari register 16-bit (contohnya dari node Modbus Read) dan mengkonversinya menjadi angka numerik (Float, Int, Uint). Mendukung opsi pembulatan desimal untuk tipe float dan secara otomatis menyembunyikan dropdown Endianness jika tipe data 16-bit dipilih.
  2. PLC Multi Value Converter: Mengonversi satu array besar register Modbus menjadi sebuah array berisi beberapa nilai tipe data numerik sekaligus. Mendukung pengaturan panjang dinamis, pembulatan desimal, dan penyembunyian otomatis input UI yang tidak relevan.
  3. Single Divide: Membagi nilai angka tunggal di msg.payload dengan angka pembagi yang ditentukan (contoh: dibagi 10 untuk mengubah 2345 menjadi 234.5).
  4. Multi Divide: Membagi setiap elemen angka di dalam array msg.payload dengan angka pembagi yang ditentukan (contoh: dibagi 10 untuk mengubah [2345, 6780] menjadi [234.5, 678.0]).
  5. PLC Write Converter: Mengkonversi angka numerik kembali menjadi array register 16-bit untuk ditulis ke PLC (contohnya melalui node Modbus Write).
  6. String Converter: Membaca array dari register 16-bit dan mengubahnya menjadi teks/string ASCII (mendukung pertukaran byte/huruf Normal dan Reverse).
  7. Write String Converter: Mengubah teks/string ASCII menjadi array register 16-bit untuk ditulis ke PLC.
  8. Unix (s) to Date: Mengonversi Unix timestamp (detik) menjadi array tanggal [Tahun, Bulan, Tanggal, Jam, Menit, Detik].
  9. Unix (ms) to Date: Mengonversi Unix timestamp (milidetik) menjadi array tanggal [Tahun, Bulan, Tanggal, Jam, Menit, Detik, Milidetik].
  10. Date to Unix (s): Mengonversi array tanggal [Tahun, Bulan, Tanggal, Jam, Menit, Detik] menjadi Unix timestamp (detik).

Berapa Jumlah Register (Array) yang Dibutuhkan?

Saat membaca atau menulis dari Modbus, tipe data yang berbeda membutuhkan jumlah register 16-bit yang berbeda pula:

  • Int16 / UInt16: Butuh 1 register (1 elemen array).
  • Int32 / UInt32: Butuh 2 register (2 elemen array).
  • Float32: Butuh 2 register (2 elemen array).
  • Float64 (Double): Butuh 4 register (4 elemen array).
  • Int64 / UInt64: Butuh 4 register (4 elemen array).
  • String:
    • Jika 1 Word = 1 Character: Butuh sebanyak jumlah huruf teks (misal 5 huruf = 5 register).
    • Jika 1 Word = 2 Characters: Butuh setengah dari jumlah huruf teks (misal 10 huruf = 5 register).

Output Node

  • Output 1 (Berhasil): Berisi nilai (atau array) hasil konversi yang sukses.
  • Output 2 (Error): Mengeluarkan pesan error jika konversi gagal (contoh: jika panjang array input dari Modbus kurang dari kebutuhan tipe data).

Example Flow

You can import this example flow directly into your Node-RED workspace (Menu > Import):

[
    {
        "id": "013b72e1d574a0f6",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "4c6ae9949798b88e",
        "type": "value-converter",
        "z": "013b72e1d574a0f6",
        "name": "",
        "endianness": "ABCD",
        "targetType": "float32",
        "x": 480,
        "y": 280,
        "wires": [
            [
                "ee5ead7d7d5af35f"
            ],
            []
        ]
    },
    {
        "id": "77ef62b3d4af500a",
        "type": "modbus-read",
        "z": "013b72e1d574a0f6",
        "name": "",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "HoldingRegister",
        "adr": "0",
        "quantity": "2",
        "rate": "500",
        "rateUnit": "ms",
        "delayOnStart": false,
        "enableDeformedMessages": false,
        "startDelayTime": "",
        "server": "6e3b57a9f8933018",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 130,
        "y": 320,
        "wires": [
            [
                "4c6ae9949798b88e"
            ],
            []
        ]
    },
    {
        "id": "ec6f4f3270362fbd",
        "type": "write-converter",
        "z": "013b72e1d574a0f6",
        "name": "",
        "endianness": "ABCD",
        "sourceType": "float32",
        "x": 550,
        "y": 580,
        "wires": [
            [
                "19bda6390147b053"
            ],
            []
        ]
    },
    {
        "id": "19bda6390147b053",
        "type": "modbus-write",
        "z": "013b72e1d574a0f6",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "",
        "dataType": "MHoldingRegisters",
        "adr": "0",
        "quantity": "2",
        "server": "6e3b57a9f8933018",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 900,
        "y": 560,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "2c1590801b58a78c",
        "type": "inject",
        "z": "013b72e1d574a0f6",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "11.234",
        "payloadType": "num",
        "x": 220,
        "y": 540,
        "wires": [
            [
                "ec6f4f3270362fbd"
            ]
        ]
    },
    {
        "id": "ee5ead7d7d5af35f",
        "type": "debug",
        "z": "013b72e1d574a0f6",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 380,
        "wires": []
    },
    {
        "id": "6e3b57a9f8933018",
        "type": "modbus-client",
        "name": "",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "127.0.0.1",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "COM10",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": 9600,
        "serialDatabits": 8,
        "serialStopbits": 1,
        "serialParity": "none",
        "serialConnectionDelay": 100,
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": 1,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectOnTimeout": true,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": true,
        "showErrors": false,
        "showWarnings": true,
        "showLogs": true
    },
    {
        "id": "cbf314c6462afc0a",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-contrib-plc-value-converter": "0.2.0",
            "node-red-contrib-modbus": "5.60.1"
        }
    }
]

Powered by Ismail Lowkey