modbusRTU over RS485: Port Not Option

This seems to be a re-occurring problem with these nodes and reading through several of the topics (including my previous one).

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:

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.

$ 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:

:face_with_symbols_over_mouth: :face_with_symbols_over_mouth: :face_with_symbols_over_mouth:

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!

1 Like

Which installer is that?

Which one of those?

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:

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

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

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. :slight_smile:

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