# Help writing 16-bit data via Modbus to a VFD

**URL:** <https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057>\
**Category:** General\
**Tags:** modbus\
**Created:** [5 September 2023 16:18 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057 "2023-09-05T16:18:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [5 September 2023 16:18 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/1 "2023-09-05T16:18:42Z")

</div>

This post is sort of the reverse of [this solved problem](https://discourse.nodered.org/t/understanding-and-parsing-16-bit-words-via-modbus/67089), where I was reading the 16-bit Modbus data from a VFD.

I have an Allen Bradley PowerFlex 525 VFD all configured via RS485 Modbus. I can read the data no problem thanks to the above linked post. For writing the data, here are the 16 bits that the VFD can accept:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4f66b06997660f6d8e0dc41fe89f1eb0eb04cdd0.png)

I am pretty lost when it comes to this. I am thinking something like this, whereby I send some decimal respresentations of the Modbus data and use the Buffer-Maker node to convert it before sending to the Modbus-Flex-Write node?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a39ddd3fd735c79b6ecc16c4138924def4abb8b.png)

```auto
[{"id":"e9a2d5a0998cb28c","type":"function","z":"46e0ed13d406fbe2","name":"Inputs to Modbus write","func":"msg.payload = {\n value: msg.payload,\n 'fc': 6,\n 'unitid': 100,\n 'address': 8192,\n 'quantity': 1\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":440,"wires":[["b3034fb7124579d1","5a94ef56a873588e"]]},{"id":"5a94ef56a873588e","type":"modbus-flex-write","z":"46e0ed13d406fbe2","name":"","showStatusActivities":false,"showErrors":false,"server":"a536fdaba00fed1f","emptyMsgOnFail":false,"keepMsgProperties":false,"x":870,"y":440,"wires":[["8f5e78ef1fe33f7f"],[]]},{"id":"8f5e78ef1fe33f7f","type":"debug","z":"46e0ed13d406fbe2","name":"debug 41","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1080,"y":440,"wires":[]},{"id":"b3034fb7124579d1","type":"debug","z":"46e0ed13d406fbe2","name":"debug 42","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":500,"wires":[]},{"id":"893f132894a4cb0c","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"271","payloadType":"num","x":110,"y":400,"wires":[["dbbdc269b30e701e"]]},{"id":"120dbdcad61a8d06","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"303","payloadType":"num","x":110,"y":480,"wires":[["dbbdc269b30e701e"]]},{"id":"dbbdc269b30e701e","type":"buffer-maker","z":"46e0ed13d406fbe2","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":310,"y":440,"wires":[["e9a2d5a0998cb28c"]]},{"id":"fb8cdd993928a92a","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"18","payloadType":"num","x":105,"y":440,"wires":[["dbbdc269b30e701e"]]},{"id":"a536fdaba00fed1f","type":"modbus-client","name":"","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"1000","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"","commandDelay":"2000","clientTimeout":"3000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":false}]

```

To start with, all I want to send is START and FORWARD, so I presume (per the above table):  
Bit 0: 0 (not stop)  
Bit 1: 1 (start)  
Bit 2: 0 (no jog)  
Bit 3: 1 (clear faults)  
Bits 4 & 5: 01 (forward command)  
Bits 6 & 6: both 0  
Bits 9, 8 and 11, 10: both 00  
Bits 14, 13, 12: 000  
Bit 15: 0

FYI, I am planning to send the command frequency setpoint (e.g. 40 Hz, or 4000) via a separate Modbus command which I believe should work (it's just a simple Function Cod 06 writing to register 8193)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b6f61684b572dc91ab15595dbd756aa4e433e678.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 September 2023 16:29 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/2 "2023-09-05T16:29:59Z")

</div>

> [@grant1](#):
>
> To start with, all I want to send is START and FORWARD, so I presume (per the above table):

Then you can simply set the value to `1` for stop or `2` for start.

in essance, that is

| bit | hex | binary | decimal |
| --- | --- | --- | --- |
| 0 | 0x0001 | `0000 0000 0000 0001` | 1 |
| 1 | 0x0002 | `0000 0000 0000 0010` | 2 |

* * *

The difficulty comes when you need to track actual value and set/clear bits before writing.

The 2nd difficulty is when you need to set multiple bits.

I recommend you make a helper function using [this code](https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798/2) - probably a good candidate for a link-call or subflow.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [5 September 2023 16:58 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/3 "2023-09-05T16:58:03Z")

</div>

Thank you, but am I even on the right track here regarding how to write the Modbus data? I have only read Modbus data in the past, so this is entirely new to me (plus I am kinda lost in the terminology...is address 8192 a register or a coil?).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2b85db33b656e4744aef6af6a1a039ac92c4affd.png)

# Modbus-Flex-Write

Modbus TCP flexible input triggered write node with connection input parameters.

Connects to a Modbus TCP or serial to write coils/registers on each incoming msg.

#### Function codes currently supported include:

- FC 5: Force Single Coil
- FC 6: Preset Single Register
- FC 15: Force Multiple Coils
- FC 16: Preset Multiple Registers

**Input parameter for connecting Modbus**

- unitid (0..255 tcp | 0..247 serial) - overrides default Unit-ID
- fc (5|6|15|16)
- start address (0:65535)
- quantity (1:65535) of coils/inputs/registers to be written from the start address

For FC 5, **msg.payload** must be a value of 1 or 0 or true or false. For FC 6, **msg.payload** must be a single value between 0:65535. For FC 16, **msg.payload** must be an array of comma separated values between 0:65535 each.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 September 2023 18:59 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/4 "2023-09-05T18:59:05Z")

</div>

Since writing these values will be infrequent, I would setup individual flows and use the basic write node instead of the flex node.

> [@grant1](#):
>
> .is address 8192 a register or a coil?).

According to your screenshot it would be FC06 AKA Preset Single Register.

Unfortunately, due to dev work, I have no modbus stuff around but I am certain if you select the correct write node, you can trigger it by a wire input and can enter the register number 8193 and `msg.payload` should be your decimal number equivalent of the bits you want to set. e.g. `1` - trigger STOP, `2` - trigger START, `0` - CLEAR ALL.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 10:42 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/5 "2023-09-06T10:42:28Z")

</div>

OK, had a chance to try this simplified approach, but am getting nothing.

I am simply injecting 1, 2 or 3 into the Modbus Write node. Flow is here:

```auto
[{"id":"46e0ed13d406fbe2","type":"tab","label":"Modbus data from VFD","disabled":false,"info":"","env":[]},{"id":"832f6fbf4698bebc","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":140,"wires":[["e1bbbca292e8ef2e"]]},{"id":"e1bbbca292e8ef2e","type":"function","z":"46e0ed13d406fbe2","name":"Inputs to Modbus call","func":"msg.payload = {\n value: msg.payload,\n 'fc': 3,\n 'unitid': 100,\n 'address': 8448,\n 'quantity': 5\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":140,"wires":[["cbc7d5e06979c4f8"]]},{"id":"cbc7d5e06979c4f8","type":"modbus-flex-getter","z":"46e0ed13d406fbe2","name":"","showStatusActivities":false,"showErrors":true,"logIOActivities":false,"server":"a536fdaba00fed1f","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":570,"y":140,"wires":[["7ffc538a510b2e77","c5a4bd89b814463c"],[]]},{"id":"7e0ee4facfa865c3","type":"influxdb out","z":"46e0ed13d406fbe2","influxdb":"8c4a32ceeeedeb64","name":"","measurement":"SingleRotaryFurnaceElementData","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"heattreat","bucket":"AMPdata","x":1280,"y":240,"wires":[]},{"id":"801560f82d87ee4b","type":"function","z":"46e0ed13d406fbe2","name":"function 1","func":"msg.payload = [\n [{\n Direction: msg.payload.status.RotatingForward\n },\n {\n MeasType: \"actual\",\n EquipElement: \"retort\",\n EquipNumber: \"6\"\n }],\n [{\n RotationalSpeed: msg.responseBuffer.data[2]/100\n },\n {\n MeasType: \"actual\",\n EquipElement: \"retort\",\n EquipNumber: \"6\"\n }]\n];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":760,"wires":[["4e66fc10637f1b09"]]},{"id":"4e66fc10637f1b09","type":"debug","z":"46e0ed13d406fbe2","name":"debug 33","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":760,"wires":[]},{"id":"10054256c158b696","type":"debug","z":"46e0ed13d406fbe2","name":"debug 34","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":300,"y":800,"wires":[]},{"id":"45f33ae7bda1e04a","type":"function","z":"46e0ed13d406fbe2","name":"function 2","func":"msg.payload = [\n [{\n Direction: msg.payload.status.RotatingForward\n },\n {\n MeasType: \"actual\",\n EquipElement: \"retort\",\n EquipNumber: \"8\"\n }],\n [{\n DriveErrorCode: msg.responseBuffer.data[1]\n },\n {\n EquipElement: \"retort\",\n EquipNumber: \"8\"\n }],\n [{\n RotationalSpeed: msg.responseBuffer.data[2] / 100\n },\n {\n MeasType: \"setpoint\",\n EquipElement: \"retort\",\n EquipNumber: \"8\"\n }],\n [{\n RotationalSpeed: msg.responseBuffer.data[3]/100\n },\n {\n MeasType: \"actual\",\n EquipElement: \"retort\",\n EquipNumber: \"8\"\n }],\n [{\n ElectricalCurrent: msg.responseBuffer.data[4]/100\n },\n {\n MeasType: \"actual\",\n EquipElement: \"retort\",\n EquipNumber: \"8\"\n }]\n];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":180,"wires":[["c7bb78791985c320","7e0ee4facfa865c3"]]},{"id":"c7bb78791985c320","type":"debug","z":"46e0ed13d406fbe2","name":"debug 36","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1260,"y":180,"wires":[]},{"id":"764ba16d3eebf71a","type":"comment","z":"46e0ed13d406fbe2","name":"Simplified version of above. Connect to 2nd output of Modbus Flex Getter. Did not correctly populate InfluxDB.","info":"","x":390,"y":720,"wires":[]},{"id":"0ea7ca6416775103","type":"debug","z":"46e0ed13d406fbe2","name":"debug 37","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1020,"y":140,"wires":[]},{"id":"c5a4bd89b814463c","type":"debug","z":"46e0ed13d406fbe2","name":"debug 38","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":100,"wires":[]},{"id":"a67e0552b9b6be99","type":"modbus-read","z":"46e0ed13d406fbe2","name":"","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"100","dataType":"HoldingRegister","adr":"027","quantity":"1","rate":"2","rateUnit":"m","delayOnStart":false,"startDelayTime":"","server":"a536fdaba00fed1f","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":130,"y":300,"wires":[["940db86e03b2bcee"],[]]},{"id":"940db86e03b2bcee","type":"function","z":"46e0ed13d406fbe2","name":"function 3","func":"msg.payload = [\n [{\n temperature: (msg.payload[0]) * (9 / 5) + 32,\n },\n {\n MeasType: \"actual\",\n EquipNumber: \"8\",\n EquipZone: \"VFD_Retort\"\n }]\n];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":300,"wires":[["0f407e0b3e2a229e","4a0344d68a1b81ab"]]},{"id":"0f407e0b3e2a229e","type":"influxdb out","z":"46e0ed13d406fbe2","influxdb":"8c4a32ceeeedeb64","name":"","measurement":"SingleRotaryFurnaceZoneData","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"heattreat","bucket":"AMPdata","x":650,"y":280,"wires":[]},{"id":"46a6bf73e5929b4a","type":"comment","z":"46e0ed13d406fbe2","name":"Temperature of VFD","info":"","x":110,"y":260,"wires":[]},{"id":"0689a93ef20be34d","type":"comment","z":"46e0ed13d406fbe2","name":"Status, Direction, Speed, Current & Error Code of VFD","info":"","x":220,"y":80,"wires":[]},{"id":"7ffc538a510b2e77","type":"buffer-maker","z":"46e0ed13d406fbe2","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":810,"y":140,"wires":[["ba25e56ebb34c869"]]},{"id":"ba25e56ebb34c869","type":"buffer-parser","z":"46e0ed13d406fbe2","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":""},{"type":"bool","name":"status=>ReadyToRun","offset":1,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"bool","name":"status=>ActiveRunning","offset":1,"length":1,"offsetbit":1,"scale":"1","mask":""},{"type":"bool","name":"status=>Forward","offset":1,"length":1,"offsetbit":2,"scale":"1","mask":""},{"type":"bool","name":"status=>RotatingForward","offset":1,"length":1,"offsetbit":3,"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":850,"y":180,"wires":[["45f33ae7bda1e04a","0ea7ca6416775103"]]},{"id":"90f17c949723088c","type":"buffer-parser","z":"46e0ed13d406fbe2","name":"","data":"payload.buffer","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":""},{"type":"bool","name":"status=>ReadyToRun","offset":1,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"bool","name":"status=>ActiveRunning","offset":1,"length":1,"offsetbit":1,"scale":"1","mask":""},{"type":"bool","name":"status=>Forward","offset":1,"length":1,"offsetbit":2,"scale":"1","mask":""},{"type":"bool","name":"status=>RotatingForward","offset":1,"length":1,"offsetbit":3,"scale":"1","mask":""},{"type":"bool","name":"status=>Accelerating","offset":1,"length":1,"offsetbit":4,"scale":"1","mask":""},{"type":"bool","name":"status=>Decelerating","offset":1,"length":1,"offsetbit":5,"scale":"1","mask":""},{"type":"bool","name":"status=>Faulted","offset":1,"length":1,"offsetbit":7,"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":130,"y":760,"wires":[["801560f82d87ee4b","10054256c158b696"]]},{"id":"4a0344d68a1b81ab","type":"debug","z":"46e0ed13d406fbe2","name":"VFD_Retort temperature","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":320,"wires":[]},{"id":"66421659a93696c3","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"45","payloadType":"num","x":90,"y":640,"wires":[["7ea908580c5fc135"]]},{"id":"7ea908580c5fc135","type":"function","z":"46e0ed13d406fbe2","name":"Inputs to Modbus write","func":"msg.payload = {\n value: msg.payload,\n 'fc': 6,\n 'unitid': 100,\n 'address': 8193,\n 'quantity': 1\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":640,"wires":[["9155d76c484df144","e2a3d9b1b1b0dba6"]]},{"id":"e2a3d9b1b1b0dba6","type":"modbus-flex-write","z":"46e0ed13d406fbe2","name":"","showStatusActivities":false,"showErrors":false,"server":"a536fdaba00fed1f","emptyMsgOnFail":false,"keepMsgProperties":false,"x":570,"y":640,"wires":[["889d5b5ad65e7e99"],[]]},{"id":"889d5b5ad65e7e99","type":"debug","z":"46e0ed13d406fbe2","name":"debug 39","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":640,"wires":[]},{"id":"9155d76c484df144","type":"debug","z":"46e0ed13d406fbe2","name":"debug 40","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":680,"wires":[]},{"id":"e9a2d5a0998cb28c","type":"function","z":"46e0ed13d406fbe2","name":"Inputs to Modbus write","func":"msg.payload = {\n value: msg.payload,\n 'fc': 6,\n 'unitid': 100,\n 'address': 8192,\n 'quantity': 1\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":460,"wires":[["b3034fb7124579d1","5a94ef56a873588e"]]},{"id":"5a94ef56a873588e","type":"modbus-flex-write","z":"46e0ed13d406fbe2","name":"","showStatusActivities":false,"showErrors":false,"server":"a536fdaba00fed1f","emptyMsgOnFail":false,"keepMsgProperties":false,"x":870,"y":460,"wires":[["8f5e78ef1fe33f7f"],[]]},{"id":"8f5e78ef1fe33f7f","type":"debug","z":"46e0ed13d406fbe2","name":"debug 41","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1080,"y":460,"wires":[]},{"id":"b3034fb7124579d1","type":"debug","z":"46e0ed13d406fbe2","name":"debug 42","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":520,"wires":[]},{"id":"58ac966d042d3316","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"271","payloadType":"num","x":310,"y":900,"wires":[["08987b674403c309"]]},{"id":"6136282e5f1afdf4","type":"debug","z":"46e0ed13d406fbe2","name":"debug 23","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":940,"wires":[]},{"id":"526f4c0ba1b974ae","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"303","payloadType":"num","x":310,"y":980,"wires":[["08987b674403c309"]]},{"id":"46162558616eca58","type":"debug","z":"46e0ed13d406fbe2","name":"debug 24","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":900,"wires":[]},{"id":"d331af2c32f60b2a","type":"buffer-parser","z":"46e0ed13d406fbe2","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":710,"y":940,"wires":[["6136282e5f1afdf4"]]},{"id":"08987b674403c309","type":"buffer-maker","z":"46e0ed13d406fbe2","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":510,"y":940,"wires":[["d331af2c32f60b2a","46162558616eca58"]]},{"id":"70b9003bdde44375","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"18","payloadType":"num","x":305,"y":940,"wires":[["08987b674403c309"]]},{"id":"893f132894a4cb0c","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"271","payloadType":"num","x":110,"y":420,"wires":[["dbbdc269b30e701e"]]},{"id":"120dbdcad61a8d06","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"303","payloadType":"num","x":110,"y":500,"wires":[["dbbdc269b30e701e"]]},{"id":"dbbdc269b30e701e","type":"buffer-maker","z":"46e0ed13d406fbe2","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":310,"y":460,"wires":[["e9a2d5a0998cb28c"]]},{"id":"fb8cdd993928a92a","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"18","payloadType":"num","x":105,"y":460,"wires":[["dbbdc269b30e701e"]]},{"id":"9ffe8a5c7048ff86","type":"modbus-write","z":"46e0ed13d406fbe2","name":"","showStatusActivities":false,"showErrors":false,"unitid":"100","dataType":"HoldingRegister","adr":"8192","quantity":"1","server":"a536fdaba00fed1f","emptyMsgOnFail":false,"keepMsgProperties":false,"x":620,"y":400,"wires":[["421d39533ba91a3d"],[]]},{"id":"5a790bfcb3e290b6","type":"inject","z":"46e0ed13d406fbe2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":430,"y":400,"wires":[["9ffe8a5c7048ff86"]]},{"id":"421d39533ba91a3d","type":"debug","z":"46e0ed13d406fbe2","name":"debug 43","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":860,"y":400,"wires":[]},{"id":"a536fdaba00fed1f","type":"modbus-client","name":"","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"1000","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"","commandDelay":"2000","clientTimeout":"3000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":false},{"id":"8c4a32ceeeedeb64","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"database","name":"","usetls":false,"tls":"","influxdbVersion":"2.0","url":"http://192.168.10.25:8086","rejectUnauthorized":true}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/601450c7362242ddf27deb5846212662279da28d.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/2919acb2a9600df73861a09fb826ab3376f97da7.png)

In all cases (injecting 1, 2 or 3), nothing changes on the VFD.

PS: I see you used register 8193 on your reply above, but am pretty sure you meant 8192. In any event, I tried both registers and no change.

---

<div class="post-metadata">

**Author:** ![Billy\_C](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/billy_c/32/74647_2.png) [@Billy\_C](https://discourse.nodered.org/u/Billy_C)\
**Post date:** [6 September 2023 12:42 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/6 "2023-09-06T12:42:40Z")

</div>

At the very least writing a 1 as the payload to 8192 should stop the VFD if it's running but commanding it to start might require some other information. Maybe??

for example, commanding 000000000000010 (2) _start_ might not do anything without a direction, therefore 000000000010010 (18) _start + forward_ would be required

Might be a good idea to confirm you are still able to read data right before you try to write as a way to eliminate any possible communication issues. You might already be doing that though.

I don't really have much to contribute as help, just going to follow along to learn.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 13:11 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/7 "2023-09-06T13:11:41Z")

</div>

Thanks for the suggestions, but just to back up a second...

Am I injecting this...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/63df7b677cb130f6c5a7e5eedabb9fdc459a2a6b.png)

or this?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1bf0b509dd2ccd9b1f1d04d62a8113b766e88c5d.png)

I tried both and neither does anything.

I am going to try to hook up a test VFD offline where I can experiment more with this. I have to believe I am missing something very fundamental. I just assumed it would be like the Read (03) command, but change the 03 to 06 (Write), but I think there are some additional things that need to be addressed.

---

<div class="post-metadata">

**Author:** ![Billy\_C](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/billy_c/32/74647_2.png) [@Billy\_C](https://discourse.nodered.org/u/Billy_C)\
**Post date:** [6 September 2023 14:02 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/8 "2023-09-06T14:02:41Z")

</div>

How was the unit-ID assigned? Was that done with a modbus write?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 14:05 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/9 "2023-09-06T14:05:17Z")

</div>

The unit-ID of 100 is what the VFD was configured with by me (parameter C124, aka RS485 Node Address). I am sure it works because I have done Modbus Read commands for over a year collecting speed, direction, current draw, etc.

In the Modbus Write node, I was specifying unit-ID to be 100.

---

<div class="post-metadata">

**Author:** ![Billy\_C](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/billy_c/32/74647_2.png) [@Billy\_C](https://discourse.nodered.org/u/Billy_C)\
**Post date:** [7 September 2023 02:20 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/10 "2023-09-07T02:20:25Z")

</div>

Oh I didn't doubt it worked. I just thought if you did some writing to it already to get the ID set then there is at least proof of concept for the write node.

---

<div class="post-metadata">

**Author:** ![JeroenVH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeroenvh/32/53766_2.png) [@JeroenVH](https://discourse.nodered.org/u/JeroenVH)\
**Post date:** [14 September 2023 10:06 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/11 "2023-09-14T10:06:42Z")

</div>

Hi @grant1,

I noticed you use the wrong syntax in your payload.  
You try to send "0000000000010010" as a number. So you actually are sending 10010 instead of 18.  
What you need to do is (if you want this notation) define it as a string and then use "parseInt" function using base 2.  
`msg.payload = parseInt(msg.payload,2);`

I often split bitranked integers that I read from devices into arrays.  
First thing is to add padding to the front of the bitstring and then slice only the last x bits you need.  
Then split the string into an array and reverse the order to have the least significant bit as array index 0.

```auto
msg.payload = ('0'.repeat(16) + msg.payload.toString(2)).slice(-16).split('').reverse()

```

Also before doing any coding in node-red, it is best to just verify communication with "modbus-poll" software. This way you get some feedback and learn quickly if the device is 0 or 1 based.  
And you can set the view to binary to toggle the correct bits.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [14 September 2023 10:09 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/12 "2023-09-14T10:09:03Z")

</div>

Thanks @JeroenVH

I will follow your tips. Unfortunately, I had to park the project because the VFD which I was trying this on had to go into a production application. My plan was to use a spare unit (if we have one) and set it up on a test bench with Modbus.

---

<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:** [13 November 2023 10:09 UTC](https://discourse.nodered.org/t/help-writing-16-bit-data-via-modbus-to-a-vfd/81057/13 "2023-11-13T10:09:08Z")

</div>

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