# Modbus : Error of lenght

**URL:** <https://discourse.nodered.org/t/modbus-error-of-lenght/33887>\
**Category:** Industrial\
**Created:** [7 October 2020 13:24 UTC](https://discourse.nodered.org/t/modbus-error-of-lenght/33887 "2020-10-07T13:24:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![INCASE](https://avatars.discourse-cdn.com/v4/letter/i/d9b06d/32.png) [@INCASE](https://discourse.nodered.org/u/INCASE)\
**Post date:** [7 October 2020 13:24 UTC](https://discourse.nodered.org/t/modbus-error-of-lenght/33887/1 "2020-10-07T13:24:52Z")

</div>

Hi all,

I'm using a P30H captor from Lummel and I would like to collect the value from the captor by the Modbus TCP/IP Protocol.

I verified the slave id, register and IP adress with Modbus Doctor.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/029968e4fd230ea725678eab52da521e14491f87.png)  
But when I tried to get the value in Node-Red, I get this error ; ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f553e8c96bd2800359687d7a116991cbe8134139.png)  
Do you have any idea for solving it ?

```auto
[{"id":"684f0762.d4f9e8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8fc69fba.ad7e1","type":"debug","z":"684f0762.d4f9e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":220,"wires":[]},{"id":"e306c8fc.aed118","type":"modbus-flex-getter","z":"684f0762.d4f9e8","name":"","showStatusActivities":true,"showErrors":true,"logIOActivities":false,"server":"5a4d7d51.7640b4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"keepMsgProperties":false,"x":510,"y":180,"wires":[["2cc5fcc0.0200e4"],["8fc69fba.ad7e1"]]},{"id":"2cc5fcc0.0200e4","type":"modbus-response","z":"684f0762.d4f9e8","name":"","registerShowMax":"100","x":750,"y":120,"wires":[]},{"id":"b5da8ef4.7de02","type":"function","z":"684f0762.d4f9e8","name":"","func":"msg.payload = { \n value: msg.payload, \n 'fc': 3, \n 'unitid': 1, \n 'address': 7500,\n 'quantity': 2\n} \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":180,"wires":[["e306c8fc.aed118"]]},{"id":"9c5dd677.2cdfc8","type":"inject","z":"684f0762.d4f9e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":110,"y":180,"wires":[["b5da8ef4.7de02"]]},{"id":"5a4d7d51.7640b4","type":"modbus-client","z":"","name":"Capteur P30H","clienttype":"tcp","bufferCommands":false,"stateLogEnabled":true,"queueLogEnabled":true,"tcpHost":"192.168.0.9","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

```

Thanks a lot for your help

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [7 October 2020 13:52 UTC](https://discourse.nodered.org/t/modbus-error-of-lenght/33887/2 "2020-10-07T13:52:27Z")

</div>

Hi,

I noticed in your function you have `value: msg.payload`

```auto
msg.payload = { 
    value: msg.payload, 
    'fc': 3, 
    'unitid': 1, 
    'address': 7500,
    'quantity': 2
} 
return msg;

```

that line i think is not necessary since you are doing a modbus Read .. not sure if that is the issue.  
[EDIT] another thing you can try is start with a leading '4' since holding registers are in the 40000 range ?  
So for address 7500 try 47500.

Based on the documentation of your device .. the modbus device reply is a 32-bit float ..  
there is a [Buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) node perfect for these type of convertions

---

<div class="post-metadata">

**Author:** ![INCASE](https://avatars.discourse-cdn.com/v4/letter/i/d9b06d/32.png) [@INCASE](https://discourse.nodered.org/u/INCASE)\
**Post date:** [7 October 2020 15:01 UTC](https://discourse.nodered.org/t/modbus-error-of-lenght/33887/3 "2020-10-07T15:01:50Z")

</div>

Thanks for your answer !  
I've try with the buffer but no answer :

```auto
[{"id":"729d145c.94f90c","type":"buffer-parser","z":"684f0762.d4f9e8","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32le","name":"item1","offset":1,"length":4,"offsetbit":0,"scale":1,"mask":""}],"swap1":"swap32","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"setTopic":true,"x":650,"y":180,"wires":[["8fc69fba.ad7e1","2cc5fcc0.0200e4"]]}]

```

Did I set the correct settings for the buffer ?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [7 October 2020 15:23 UTC](https://discourse.nodered.org/t/modbus-error-of-lenght/33887/4 "2020-10-07T15:23:16Z")

</div>

First we need to get a reply from your device? Do you get a reply now ?

The buffer-parser can be used directly after your Modbus flex getter and is used only for converting different buffer data types by passing the **msg.responseBuffer.buffer** to it.

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

Possible settings could be the following. Depending on your device maybe Swap 16 or float(le)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e17def3a5decd8d68561eef459dd7ae29377625a.png)

---

<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:** [6 December 2020 15:23 UTC](https://discourse.nodered.org/t/modbus-error-of-lenght/33887/5 "2020-12-06T15:23:17Z")

</div>

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