# How to do a proper Modbus Data Acquisition and display

**URL:** <https://discourse.nodered.org/t/how-to-do-a-proper-modbus-data-acquisition-and-display/45643>\
**Category:** General\
**Created:** [14 May 2021 13:20 UTC](https://discourse.nodered.org/t/how-to-do-a-proper-modbus-data-acquisition-and-display/45643 "2021-05-14T13:20:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samsaminou](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@Samsaminou](https://discourse.nodered.org/u/Samsaminou)\
**Post date:** [14 May 2021 13:20 UTC](https://discourse.nodered.org/t/how-to-do-a-proper-modbus-data-acquisition-and-display/45643/1 "2021-05-14T13:20:02Z")

</div>

Node-RED version : v.0.15.3

Hello to everybody,

Beginner in Nodered, I am currently working on a Modbus data acquisition system with Nodered.  
First of all, I managed to get the address of a counter, and to build a modbus frame according to the Modbus protocol (RS485).  
Secondly, I managed to display on the debug the values of the modbus frame and to display them.

I would like to be able to recover the payload object that it sends us (the multi serial) in a table.  
I wanna be able to cut and keep only the values between the brackets and delete the rest (here my registers refer to the kwH) (Screen below). And then allow to convert the hexadecimal values of the frame into decimal on the display tab

Does anyone know how to do this? And is it possible to create a global variable?

Excuse me, I think that my "fonction de test" node must contain a lot of errors.

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

Here is my flow code :

```auto
[{"id":"c2d776a2.9ebe68","type":"tab","label":"Node TEST"},{"id":"1d132f6a.05eaa1","type":"function","z":"c2d776a2.9ebe68","name":"write trame","func":"var buf=Buffer([0x02,0x03,0xC6,0x52,0x00,0x02,0x59,0x61]);\nmsg.payload=buf;\nreturn msg;\n","outputs":1,"noerr":0,"x":408,"y":194,"wires":[["a06d32f3.fd2b2","9b3b4bb1.74b2b8"]]},{"id":"44ec0cf0.b63024","type":"inject","z":"c2d776a2.9ebe68","name":"payload","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":150,"y":195,"wires":[["1d132f6a.05eaa1"]]},{"id":"95fea1ef.6353b","type":"debug","z":"c2d776a2.9ebe68","name":"","active":true,"console":"false","complete":"true","x":744,"y":423,"wires":[]},{"id":"a06d32f3.fd2b2","type":"debug","z":"c2d776a2.9ebe68","name":"","active":true,"console":"false","complete":"payload","x":746,"y":194,"wires":[]},{"id":"a05ecf98.bcd35","type":"multi serial in","z":"c2d776a2.9ebe68","name":"","accessoryport":"2","mode":"rs485hd","serialbaud":"9600","datatype":"readbytes","flowcontrol":"disabled","xonxoff":null,"rtscts":null,"dsrdtr":null,"startstopchars":"false","databits":8,"stopbits":1,"timeout":"1","bytecount":"1","parity":"none","x":136.10000610351562,"y":420,"wires":[["95fea1ef.6353b"]]},{"id":"9b3b4bb1.74b2b8","type":"multi serial out","z":"c2d776a2.9ebe68","name":"","accessoryport":"2","mode":"rs485hd","serialbaud":"9600","datatype":"readbytes","flowcontrol":"disabled","xonxoff":null,"rtscts":null,"dsrdtr":null,"startstopchars":"false","databits":8,"stopbits":1,"parity":"none","x":742.1000747680664,"y":326.0000066757202,"wires":[]},{"id":"2990e6d1.4bf94a","type":"function","z":"c2d776a2.9ebe68","name":"fonction test","func":"var count=global.get('msg.payload') || 0;\nvar payload=context.get('msg.payload') || {};\nif (payload.count===undefined)//test exists\n{\n payload.count=0;\n}\npayload.count +=1;\nglobal.set('msg.payload',count);\nmsg.payload=\"msg.payload \"+msg.payload+\" \"+payload.count;\ncontext.set('msg.payload',payload);\nreturn msg.payload;\n\n\n//var payload=msg.payload;\n//var trame = {};\n/*global.set(\"Message Payload\",msgpayload);\nmsg.payload = global.get(\"payload\");\n\nreturn msg;\n*/","outputs":1,"noerr":0,"x":350.16668701171875,"y":492.3333740234375,"wires":[[]]},{"id":"834f70a2.655b","type":"function","z":"c2d776a2.9ebe68","name":"","func":"return payload;","outputs":1,"noerr":0,"x":451,"y":366,"wires":[[]]}]

```

---

<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:** [14 May 2021 13:23 UTC](https://discourse.nodered.org/t/how-to-do-a-proper-modbus-data-acquisition-and-display/45643/2 "2021-05-14T13:23:52Z")

</div>

> [@Samsaminou](#):
>
> I wanna be able to cut and keep only the values between the brackets and delete the rest

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![Samsaminou](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@Samsaminou](https://discourse.nodered.org/u/Samsaminou)\
**Post date:** [24 May 2021 08:58 UTC](https://discourse.nodered.org/t/how-to-do-a-proper-modbus-data-acquisition-and-display/45643/3 "2021-05-24T08:58:57Z")

</div>

I don't have the appearance of buttons under my mouse pointer when i over hover a debug message.

I mentionned the version of my NodeRED at the top of my topic which is versions away in my opinion of the version you got, giving the possibility to do this.

I wanna have more information to know how to acquire the hexa variable i've put in a buffer that i wanna turn into a global variable so i can split the informations contained in the Modbus frame and display them properly instead of having values in brackets .

---

<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:** [24 May 2021 09:04 UTC](https://discourse.nodered.org/t/how-to-do-a-proper-modbus-data-acquisition-and-display/45643/4 "2021-05-24T09:04:33Z")

</div>

> [@Samsaminou](#):
>
> I don't have the appearance of buttons under my mouse pointer when i over hover a debug message.
> 
> I mentionned the version of my NodeRED at the top of my topic

Can you not upgrade node-red? That is quite old and you are missing out on some great features.

> [@Samsaminou](#):
>
> I wanna have more information to know how to acquire the hexa variable i've put in a buffer that i wanna turn into a global variable so i can split the informations contained in the Modbus frame and display them properly instead of having values in brackets .

There is a contrib node called node-red-contrib-buffer-parser that's perfect for turning all your modbus raw data into nicely formatted values but I am going to guess from your very old version of node-red that your node version is also too old.

What does `node -v` report?

---

<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:** [23 July 2021 09:04 UTC](https://discourse.nodered.org/t/how-to-do-a-proper-modbus-data-acquisition-and-display/45643/5 "2021-07-23T09:04:39Z")

</div>

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