Modbus rtu issue with USB-RS485 adaptor "cannot lock port" on RPI

this works on windows


but getting
20 Oct 17:32:30 - [warn] [modbus-read:calling for data in 2007] Modbus Failure On State sending Get More About It By Logging
20 Oct 17:32:30 - [error] [modbus-read:calling for data in 2007] Timed out

this is the flow

.. not sure if im doing something wrong?

Debian blocks port 502 by default. Install UFW and keep it disabled. This will open port 502, or change all to port 1502.

Modbus RTU does not use port 502, i cannot see a reason why this should solve the issue?

Syma33, you are indeed correct, somehow my brain registered Modbus TCP.
Will have a look into this over the weekend, and see if I can help you out.

I use /dev/serial0 on the Pis I work with.

Also, when debugging, I turn on all the "Show..." options for the node.

And if you're using Docker, there are some other things to consider which I discovered along the way, recorded for your amusement here.

im not using Docker... Tried change to /dev/serial1 and got same issue

Is this a USB to serial? Bluetooth serial? built in?

Have you tried other settings?

try /dev/ttyUSB0 or /dev/ttyACM0 for USB device
try /dev/serial1 or /dev/ttyAMA0 for 2nd serial port
try /dev/serial0 or /dev/ttyS0 for the build in ttl serial

usb to serial(rs485) adapter

no listed /dev/ttyUSB0, tried /dev/ttyACM0

/dev/ ls when adapter plugged in..


/dev/ ls when adapter unplugged.. (/dev/serial1 and /dev/ttyACM0 appears, tried both of them in NR)

settings..

On a side note, you know you can paste images from clipboard into a reply (without using imgur) (or drag them in)

Do you have any documentation or a link to documentation?

Have you see it work outside of node-red?

Well, it works in windowsbased but i havnt found a reliable python script for testing it out in the raspberry pi.

Tried connections again and got "port not open" in terminal

did run

DEBUG=contribModbus*,modbus-serial node-red -v

Perhaps the device is not compatible with Linux/RPi some software / update / configuration before use?

Again, do you have any documentation or a link to documentation? OR at minimum, the make + model?

"cannot lock port"

Isnt this a permissions issue?

Search this forum and the net - there are a few threads on this.

pi@rpizheat:/dev/serial/by-id $ ls
usb-Exar_Corp._XR21B1411_M4125347551-if00

should work with linux syst...and npm and node -v
6.14.8
v12.19.0
Raspbian GNU/Linux 10 (buster)

not sure, if im running "node-red-start" as user pi, its already got permissions for dialout group.

"cannot lock port" often means some other app is already trying to talk to the port and it won't share it. You need to stop any other apps using it first.

disconnected usb-adapter and reconnected to another raspberry pi, still same issue. Must

Tried
sudo lsof /dev/ttyACM0 while runnings NR and got this.
bild

seems to open modbus rtu and close, but having issue reading..

Check permissions on the unit.

I had this recently with a USB/RS485 adapter.

When plugged in - it creates the port ttyUSB0 - this is in the /dev/folder

By default only members of the Dialout group have access to this to read and write.

As a test you can chmod it for the user you are running NR as, but this will be lost when you next unplug or restart

You need to add the NR running user to the Dialout group or add in a rules.d script to change the rights each time the device is initialized

This was my solution on Ubuntu on a laptop recently.

Even after all of this i could not get the node-red-contrib-modbus to workout - had to go to modbus-serial to get it to work.

Been running happily for 10 days in test mode polling an energy meter every 10 seconds.

Craig

Craig

1 Like

i think i solved it, was driver issue related to xr21b1411. This is how i solved it.

sudo apt install git bc bison flex libssl-dev
sudo wget https://raw.githubusercontent.com/RPi-Distro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source && sudo chmod +x /usr/local/bin/rpi-source && /usr/local/bin/rpi-source -q --tag-update
rpi-source
git clone https://github.com/kasbert/epsolar-tracer.git
cd epsolar-tracer
cd xr_usb_serial_common-1a
make 
rmmod cdc-acm
modprobe -r usbserial
modprobe usbserial
insmod ./xr_usb_serial_common.ko
sudo echo blacklist cdc-acm > /etc/modprobe.d/blacklist-cdc-acm.conf
update-initramfs -u

In NR, change RTU to RTU-bufferd

Good stuff.

I marked your post as the solution and updated the title to help future users with same issue.

1 Like