# modbusRTU over RS485: Port Not Option

**URL:** https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204
**Category:** General
**Created:** [3 April 2023 15:12 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204 "2023-04-03T15:12:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)
#### Post date: [3 April 2023 15:12 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/1 "2023-04-03T15:12:48Z")

</div>

This seems to be a re-occurring problem with these nodes and reading through several of the topics (including my previous [one](https://discourse.nodered.org/t/modbus-tcp-inconsistencies-issues/64032)).

This time I'm trying to connect to a serial device. It was working on a Tulip Edge IO device using their ancient Node Red 1.3.5. At some point `node-red-contrib-modus` was updated to no longer be compatible with 1.X so I put Fedora Linux on a tablet and installed Node Red 3.0.2 (and the latest `node-red-contrib-modbus`).

Using a catch node I can get the following very unhelpful error:

```auto
Error: Port Not Open
    at /home/nodered/.node-red/node_modules/node-red-contrib-modbus/modbus/maps/core/core/modbus-client-core.js:79:156

```

Looking at line 79 of the file on github seems to be for closing the port. So am I to assume it's trying to close a port that's not open?

Furthermore, the documentation for `node-red-contrib-modbus` is very confusing. At the top it says it's BASED on `modbus-serial`, but in the details says to test using `modbus-serial` if you have issues.

Which I did with what I think is success. I don't have the controller I'm trying to talk to while I'm troubleshooting in the lab but I can see the TX light blink on the USB-\>RS485 adapter when I run the following script and do not see a blink when I click the inject node in NR.

```auto
$ cat modbus-test.js
const ModbusRTU = require('modbus-serial');

const client = new ModbusRTU();
client.connectRTUBuffered('/dev/ttyUSB0', { baudRate: 19200 }, (err) => {
  if (err) {
    console.error(err);
    return;
  }

  client.setID(1); // Modbus slave address
  client.setTimeout(500);
  const start = 2000; // starting register address
  const quantity = 10; // number of registers to read

  client.readHoldingRegisters(start, quantity)
    .then((data) => {
      console.log(data); // do something with the received data
    })
    .catch((err) => {
      console.error(err); // handle error
    })
    .finally(() => {
      client.close(); // close connection after the operation is complete
    });
});

```

For posterity here's the flow:

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

---

<div class="post-metadata">

### Author: ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)
#### Post date: [3 April 2023 17:32 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/2 "2023-04-03T17:32:12Z")

</div>

🤬 🤬 🤬

I had COMPLETELY FORGOTTEN that by default the installer creates a `nodered` user rather than install as the current user.

Added `nodered` to the `dialout` group and now it can open the port!

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [3 April 2023 18:56 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/3 "2023-04-03T18:56:43Z")

</div>

> [@hobbes1069](#):
>
> the installer creates a `nodered` user

Which installer is that?

---

<div class="post-metadata">

### Author: ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)
#### Post date: [3 April 2023 19:22 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/4 "2023-04-03T19:22:52Z")

</div>

> **[GitHub - node-red/linux-installers: Node-RED install scripts for various...](https://github.com/node-red/linux-installers)**
>
> Node-RED install scripts for various flavours of Linux - GitHub - node-red/linux-installers: Node-RED install scripts for various flavours of Linux

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [3 April 2023 20:02 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/5 "2023-04-03T20:02:44Z")

</div>

Which one of those?

---

<div class="post-metadata">

### Author: ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)
#### Post date: [3 April 2023 20:16 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/6 "2023-04-03T20:16:13Z")

</div>

Sorry, had to be quick as I had a meeting to get to...

The RPM method (Since it's Fedora Linux).

Looks like it's related to this commit:

> <https://github.com/node-red/linux-installers/commit/3be6ae01407bee4655263a8bfeb669ce9737d3b1>
>
> \- \[x\] install for another user by setting environment variable e.g. \`NODERED\_USE…R=test\`
> \- \[x\] suggest user \`nodered\` during install when environment variable \`NODERED\_USER\` is not set.
> \- \[x\] comment low memory NODE OPTIONS
> \- \[x\] correct environmentFile, to /etc/node-red/environment
> \- \[x\] add some color to differentiate users
> \- \[x\] can be started as root or normal user, will prompt for password for sudo

It changed a little over a year ago but I haven't used it on a fresh install in a while.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [3 April 2023 20:30 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/7 "2023-04-03T20:30:41Z")

</div>

OK, that appears to be specific to the rpm version. I wonder why that was done.

---

<div class="post-metadata">

### Author: ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)
#### Post date: [18 April 2023 23:24 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/8 "2023-04-18T23:24:24Z")

</div>

I don't think it's necessarily a bad idea. Flowforge does the same thing, but some reminders about WHO needs to be in the dialout group would be good. 🙂

---

<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: [9 May 2023 14:35 UTC](https://discourse.nodered.org/t/modbusrtu-over-rs485-port-not-option/77204/10 "2023-05-09T14:35:30Z")

</div>

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