[
    {
        "id": "27aea651d2a2546b",
        "type": "tab",
        "label": "01 - Fixed",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "82ad4c5a203f48ba",
        "type": "catch",
        "z": "27aea651d2a2546b",
        "name": "",
        "scope": null,
        "uncaught": false,
        "x": 120,
        "y": 360,
        "wires": [
            [
                "15fb14a2d2f471cd"
            ]
        ]
    },
    {
        "id": "15fb14a2d2f471cd",
        "type": "debug",
        "z": "27aea651d2a2546b",
        "name": "EXCEPTION",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 310,
        "y": 360,
        "wires": []
    },
    {
        "id": "7fce9d5517ce047d",
        "type": "modbus-dynamic-server",
        "z": "27aea651d2a2546b",
        "name": "",
        "server": "99d6be6157571b79",
        "x": 190,
        "y": 240,
        "wires": [
            [
                "412f61bb3198e915"
            ]
        ]
    },
    {
        "id": "0fdcef6bc2eda10b",
        "type": "comment",
        "z": "27aea651d2a2546b",
        "name": "Receive a modbus request",
        "info": "",
        "x": 170,
        "y": 200,
        "wires": []
    },
    {
        "id": "0d0dc01dd45da0da",
        "type": "comment",
        "z": "27aea651d2a2546b",
        "name": "Fixed Response Example",
        "info": "",
        "x": 170,
        "y": 60,
        "wires": []
    },
    {
        "id": "cde13265ac01ba74",
        "type": "comment",
        "z": "27aea651d2a2546b",
        "name": "Catch and report any exceptions",
        "info": "",
        "x": 190,
        "y": 320,
        "wires": []
    },
    {
        "id": "412f61bb3198e915",
        "type": "function",
        "z": "27aea651d2a2546b",
        "name": "Generate Response",
        "func": "/*\n * The modbus-dynamic-server-response node expects:\n *\n * - For FC3 / FC4 (register reads):\n *   - An array → interpreted as 16-bit register values (uint16)\n *   - A Buffer → interpreted as raw register bytes (exactly as provided)\n * - For FC1 / FC2 (bit reads):\n *   - An array -> interpreted as boolean / bit values, e.g.\n *     [true, false, true, ...]\n *   - A Buffer -> interpreted as packed bit values\n * \n * The response node works at the Modbus register / bit level.\n * It does NOT infer higher-level types such as float32, int32, etc.\n * If you need to return those types, you must encode them into registers\n * yourself (typically using a Buffer).\n *\n * - For exceptions:\n *   msg.payload = { exception: <code> }\n */\n \nif (msg.payload.fc !== 3 && msg.payload.fc !== 4) {\n    msg.payload = { exception: 1 }; // Illegal Function\n    return msg;\n}\n\nconst address = Number(msg.payload.address ?? 0);\nconst quantity = Math.max(1, Number(msg.payload.quantity ?? 1));\n\nconst values = [];\nfor (let i = 0; i < quantity; i++) {\n    values.push((address + i) * 2);\n}\n\nmsg.payload = values;\nreturn msg;\n\n\n/*\n * Example: return one float32 value for an FC3 / FC4 request.\n *\n * Modbus uses 16-bit registers, so a float32 spans two registers (4 bytes).\n *\n * Note: Different Modbus clients may expect different byte / word ordering.\n *\n * Standard Big Endian (ABCD) is most common and corresponds to:\n *   buf.writeFloatBE(value)\n *\n * Some devices use \"word-swapped\" order (CDAB):\n *   [A B C D] -> [C D A B]\n *\n * const value = 123.456;\n * const buf = Buffer.alloc(4);\n *\n * // Write standard ABCD (Big Endian)\n * buf.writeFloatBE(value, 0);\n *\n * // Convert to CDAB (word swap) ONLY if required\n * const swapped = Buffer.alloc(4);\n * buf.copy(swapped, 0, 2, 4); // CD\n * buf.copy(swapped, 2, 0, 2); // AB\n *\n * // Use one of these depending on client expectations:\n * msg.payload = buf;      // ABCD (most common)\n * // msg.payload = swapped; // CDAB (word-swapped)\n *\n * return msg;\n */",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 240,
        "wires": [
            [
                "9c7efb90e8be1480"
            ]
        ]
    },
    {
        "id": "9c7efb90e8be1480",
        "type": "modbus-dynamic-server-response",
        "z": "27aea651d2a2546b",
        "name": "",
        "x": 840,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "2fb21a3fb56e3844",
        "type": "comment",
        "z": "27aea651d2a2546b",
        "name": "Send the response",
        "info": "",
        "x": 810,
        "y": 200,
        "wires": []
    },
    {
        "id": "52f29271796c82ce",
        "type": "comment",
        "z": "27aea651d2a2546b",
        "name": "Generate the response",
        "info": "",
        "x": 500,
        "y": 200,
        "wires": []
    },
    {
        "id": "1b542f2233fb0345",
        "type": "comment",
        "z": "27aea651d2a2546b",
        "name": "Note: the server config for this example listens on port 1503",
        "info": "",
        "x": 490,
        "y": 120,
        "wires": []
    },
    {
        "id": "99d6be6157571b79",
        "type": "modbus-dynamic-server-config",
        "name": "",
        "host": "0.0.0.0",
        "port": "1503",
        "enforceResponseOrder": true,
        "pendingResponseTimeout": 300000
    },
    {
        "id": "7b158e2aa23b10de",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-modbus-dynamic-server": "0.1.0"
        }
    }
]