# How to read data from ML Using modbus-serial function code

**URL:** <https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696>\
**Category:** General\
**Created:** [25 December 2022 20:43 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696 "2022-12-25T20:43:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![akshayjain](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@akshayjain](https://discourse.nodered.org/u/akshayjain)\
**Post date:** [25 December 2022 20:43 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696/1 "2022-12-25T20:43:09Z")

</div>

Hi there, i have an example of modbus-serial and i installed it via npm install modbus-serial  
and i got an example but this example has some error which i am not getting it how to solve so can anyone check what is the issue and why the error are coming.

```auto
var modbus = require('modbus-serial');

var client = new modbus.client.RTU(
    '/dev/ttyUSB0', // Replace this with the path to your serial port
    {
        baudRate: 9600,
        dataBits: 8,
        stopBits: 1,
        parity: 'even'
    }
);

client.writeHoldingRegisters(40010, [1]) // Write the value 1 to address 40010
    .then(function() {
        console.log('Success');
    })
    .catch(function(err) {
        console.error(err);
    });

```

---

<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:** [25 December 2022 21:03 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696/2 "2022-12-25T21:03:32Z")

</div>

There are modbus nodes you can install from the palette - no need for DIY code

---

<div class="post-metadata">

**Author:** ![akshayjain](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@akshayjain](https://discourse.nodered.org/u/akshayjain)\
**Post date:** [26 December 2022 06:13 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696/3 "2022-12-26T06:13:09Z")

</div>

Why can't you help with this, this is also an example from modbus-serial

---

<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:** [26 December 2022 06:28 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696/4 "2022-12-26T06:28:00Z")

</div>

Why don't you want to use the modbus nodes?  
Why do you want to hand code this?

---

<div class="post-metadata">

**Author:** ![akshayjain](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@akshayjain](https://discourse.nodered.org/u/akshayjain)\
**Post date:** [26 December 2022 11:00 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696/5 "2022-12-26T11:00:09Z")

</div>

I don't know how to use modbus for rs232 serial communication can you please give me some examples of it

---

<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:** [26 December 2022 11:13 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696/6 "2022-12-26T11:13:30Z")

</div>

Search the forum. Modbus is heavily discussed here.

As for examples [node-red-contrib-modbus](https://flows.nodered.org/node/node-red-contrib-modbus) has built-in examples (use `Ctrl-i` in the node-red editor to access built-in examples

---

<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:** [24 February 2023 11:14 UTC](https://discourse.nodered.org/t/how-to-read-data-from-ml-using-modbus-serial-function-code/72696/7 "2023-02-24T11:14:29Z")

</div>

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