# Using a Switch Node to parse a Modbus Read Array

**URL:** https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007
**Category:** General
**Created:** [20 May 2021 23:28 UTC](https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007 "2021-05-20T23:28:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mgkeekrog](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mgkeekrog](https://discourse.nodered.org/u/mgkeekrog)
#### Post date: [20 May 2021 23:28 UTC](https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007/1 "2021-05-20T23:28:02Z")

</div>

I'm reading 16 consecutive Modbus Input Contacts (i.e., function code 2) on a digital input card and the result from the Modbus node is an array of 16 elements. I'd like to use the Switch node to parse the 16 element array into 16 paths so I can use each pin of the Switch node to set tags with the associated Boolean values.  
My Modbus array result:  
 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c8f12cdec0c5756129d1082fd04986f67e70394.jpeg)

My Switch Node Configuration which is not working:

 ![Capture2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8cabd5054a72df1dd680787990ed417831d4cef7.jpeg)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [21 May 2021 00:30 UTC](https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007/2 "2021-05-21T00:30:24Z")

</div>

If you want each element of the array sent to diffeent outputs.

here is an example.

```auto
[{"id":"449af8d3.050b68","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[false,false,false]","payloadType":"json","x":150,"y":2020,"wires":[["71bb8075.c7fc48"]]},{"id":"71bb8075.c7fc48","type":"split","z":"c74669a0.6a34f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":370,"y":2020,"wires":[["10edad9.21280d2"]]},{"id":"10edad9.21280d2","type":"switch","z":"c74669a0.6a34f8","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":560,"y":2020,"wires":[["5369c443.3d6454"],["2863627c.de639e"],["a570b87f.d22fe8"]]},{"id":"5369c443.3d6454","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":2000,"wires":[]},{"id":"2863627c.de639e","type":"debug","z":"c74669a0.6a34f8","name":"out 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":2040,"wires":[]},{"id":"a570b87f.d22fe8","type":"debug","z":"c74669a0.6a34f8","name":"out 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":2080,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![mgkeekrog](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mgkeekrog](https://discourse.nodered.org/u/mgkeekrog)
#### Post date: [21 May 2021 14:01 UTC](https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007/3 "2021-05-21T14:01:10Z")

</div>

Very cool solution - thank you very much E1cid!

---

<div class="post-metadata">

### Author: ![mgkeekrog](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mgkeekrog](https://discourse.nodered.org/u/mgkeekrog)
#### Post date: [21 May 2021 15:42 UTC](https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007/4 "2021-05-21T15:42:41Z")

</div>

E1cid,

Would you know how to prevent the first msg.payload from the Split node to not pass an object and only the boolean payload. All other sequential msg.payload work great and pass a boolean value. See below.

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a69bac9f9ecdb81c0231643c17b75b145e2bd81c.jpeg)

---

<div class="post-metadata">

### Author: ![mgkeekrog](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mgkeekrog](https://discourse.nodered.org/u/mgkeekrog)
#### Post date: [21 May 2021 15:48 UTC](https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007/5 "2021-05-21T15:48:30Z")

</div>

E1cid,  
Sorry about that previous question. I see your code simply enabled the complete message object in the debug node. I'm all set. Thank you,

---

<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: [20 July 2021 15:49 UTC](https://discourse.nodered.org/t/using-a-switch-node-to-parse-a-modbus-read-array/46007/6 "2021-07-20T15:49:13Z")

</div>

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