Sending modbus bit

Hi,

I have modbus control for power that works because bit 0, but if I want to control fan speed I have to use bit 12-15. Can you help me on how to do it?

thanks

[
    {
        "id": "bced3dc5da31bb7a",
        "type": "debug",
        "z": "0de2fcb7c52ddc84",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1210,
        "y": 320,
        "wires": []
    },
    {
        "id": "d52474f17c2c94cd",
        "type": "modbus-write",
        "z": "0de2fcb7c52ddc84",
        "name": "power 2000",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "2000",
        "quantity": "1",
        "server": "31b3b9976cf2bddc",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 1030,
        "y": 340,
        "wires": [
            [
                "bced3dc5da31bb7a"
            ],
            []
        ]
    },
    {
        "id": "1105add276c6b266",
        "type": "inject",
        "z": "0de2fcb7c52ddc84",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 850,
        "y": 360,
        "wires": [
            [
                "d52474f17c2c94cd"
            ]
        ]
    },
    {
        "id": "a59a858968ea6b25",
        "type": "inject",
        "z": "0de2fcb7c52ddc84",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 850,
        "y": 320,
        "wires": [
            [
                "d52474f17c2c94cd"
            ]
        ]
    },
    {
        "id": "31b3b9976cf2bddc",
        "type": "modbus-client",
        "name": "MODBUS",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.28.202",
        "tcpPort": "10502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": false,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true,
        "showErrors": false,
        "showWarnings": true,
        "showLogs": true
    }
]

You will need to read the value, mask the bit on/off and send the full WORD value back

To mask the bits on/off, use a function node. e.g: Node-red-contrib-remote-io, digital output for joining bool to word - #2 by Steve-Mcl

Alternatively, use the buffer-maker and buffer-parser nodes to conver your data to/from BOOLS in the node-red-contrib-buffer-parser package.

this document modbus

I try it to read modbus state power, fan speed and bit
result this

write modbus register address
2030 : power&fan speed
2031 : mode
2032 : setpoint
read modbus register address:
2060 : power&fan speed
2061 : mode
2062 : setpoint

[{"id":"880c9fb2aff63126","type":"modbus-read","z":"3a6301a4.44064e","name":"","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"showWarnings":true,"unitid":"2","dataType":"InputRegister","adr":"2060","quantity":"6","rate":"1","rateUnit":"h","delayOnStart":false,"startDelayTime":"","server":"4baeb19a89ea1516","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":130,"y":580,"wires":[["32cb358fbd4ef284","7b6de22caa16aba4"],[]]},{"id":"32cb358fbd4ef284","type":"buffer-maker","z":"3a6301a4.44064e","name":"","specification":"spec","specificationType":"ui","items":[{"name":"item1","type":"uint16be","length":1,"dataType":"msg","data":"payload"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","x":350,"y":600,"wires":[["07eb1757d3970a03"]]},{"id":"7b6de22caa16aba4","type":"function","z":"3a6301a4.44064e","name":"read modbus","func":"msg.payload = {\n    power: msg.payload[0] & 1,\n    fan_speed: (msg.payload[0] >> 12) & 7\n\n};\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":540,"wires":[["48235995625ce4b0"]]},{"id":"07eb1757d3970a03","type":"buffer-parser","z":"3a6301a4.44064e","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"decimal","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"16bitbe","name":"binary","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":510,"y":600,"wires":[["48235995625ce4b0"]]},{"id":"48235995625ce4b0","type":"debug","z":"3a6301a4.44064e","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":850,"y":600,"wires":[]},{"id":"37c416aa94d3e1a1","type":"modbus-write","z":"3a6301a4.44064e","name":"Power 2030","showStatusActivities":false,"showErrors":false,"showWarnings":true,"unitid":"2","dataType":"HoldingRegister","adr":"2030","quantity":"1","server":"4baeb19a89ea1516","emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":290,"y":700,"wires":[["48235995625ce4b0"],[]]},{"id":"92d7d9899886a56e","type":"inject","z":"3a6301a4.44064e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":720,"wires":[["37c416aa94d3e1a1"]]},{"id":"1a54cadffe125476","type":"inject","z":"3a6301a4.44064e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":680,"wires":[["37c416aa94d3e1a1"]]},{"id":"4baeb19a89ea1516","type":"modbus-client","name":"MODBUS NEW","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"192.168.28.202","tcpPort":"10502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":2,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true,"showErrors":false,"showWarnings":true,"showLogs":true}]

Until now I have not been able to control the fan speed.

Why do you have buffer maker before buffer parser? That will overwrite incoming payload.

For reading, you should read -> parse (to friendly object with nice names props).

For writing, you must use current state and set/update any bits you wish to change. So ...

Read (get good/latest values) > parse (to get user friendly format) > change node (to update bit/nibble) > maker (to pack the bits/flags/nibbles into bytes) > parser (to make 16bit unsigned integer array) > write node.