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

**URL:** <https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586>\
**Category:** General\
**Created:** [20 October 2020 16:34 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586 "2020-10-20T16:34:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [20 October 2020 16:34 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/1 "2020-10-20T16:34:27Z")

</div>

this works on windows

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f5eb65cba8c887037e6c8c317980dd484d8a9af.png)  
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

> **[\[{"id":"899652c6.b9c0d","type":"tab","label":"Flow...](https://pastebin.com/ufxviiLf)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

.. not sure if im doing something wrong?

---

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [21 October 2020 08:00 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/2 "2020-10-21T08:00:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [21 October 2020 14:54 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/3 "2020-10-21T14:54:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [21 October 2020 21:08 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/4 "2020-10-21T21:08:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kpm\_at\_hfi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kpm_at_hfi/32/11372_2.png) [@kpm\_at\_hfi](https://discourse.nodered.org/u/kpm_at_hfi)\
**Post date:** [21 October 2020 23:46 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/5 "2020-10-21T23:46:45Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![kpm\_at\_hfi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kpm_at_hfi/32/11372_2.png) [@kpm\_at\_hfi](https://discourse.nodered.org/u/kpm_at_hfi)\
**Post date:** [21 October 2020 23:49 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/6 "2020-10-21T23:49:15Z")

</div>

And if you're using Docker, there are some other things to consider which I discovered along the way, recorded for your amusement [here](https://stackoverflow.com/questions/58100451/having-trouble-accessing-dev-serial0-on-a-raspi-from-within-a-module-in-azure-i).

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [22 October 2020 16:44 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/7 "2020-10-22T16:44:38Z")

</div>

im not using Docker... Tried change to /dev/serial1 and got same issue  
 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70caa3dc53d0a4fbc359bb5d4de741da38b09520.png)

---

<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:** [22 October 2020 18:50 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/8 "2020-10-22T18:50:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [22 October 2020 19:04 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/9 "2020-10-22T19:04:39Z")

</div>

> [@Steve-Mcl](#):
>
> Is this a USB to serial? Bluetooth serial? built in?

usb to serial(rs485) adapter

> [@Steve-Mcl](#):
>
> try /dev/ttyUSB0 or /dev/ttyACM0 for USB device

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

/dev/ ls when adapter plugged in..

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/22323ff546532920b027f9776d98faa60da5095d.png)  
/dev/ ls when adapter unplugged.. (/dev/serial1 and /dev/ttyACM0 appears, tried both of them in NR)  
 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39330a22cc80c3da610c9476439d19e00fe841b0.png)  
settings..  
 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efee086030990edafec4146fee0c6c77bc8dad6f.png)

---

<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:** [22 October 2020 19:07 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/10 "2020-10-22T19:07:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [22 October 2020 19:13 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/11 "2020-10-22T19:13:49Z")

</div>

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

 ![bild](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39d009bf8c5827f05e4948641f1a2dd9c4e52b5b.png)

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [22 October 2020 19:21 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/12 "2020-10-22T19:21:21Z")

</div>

did run

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

```

 ![bild](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9d63ce0027d418e3d8e99e9501d25f01a205718.png)

---

<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:** [22 October 2020 19:21 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/13 "2020-10-22T19:21:26Z")

</div>

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?

---

<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:** [22 October 2020 19:23 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/14 "2020-10-22T19:23:45Z")

</div>

> "cannot lock port"

Isnt this a permissions issue?

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

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [22 October 2020 19:32 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/15 "2020-10-22T19:32:52Z")

</div>

> [@Steve-Mcl](#):
>
> Again, do you have any documentation or a link to documentation?

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)

> [@Steve-Mcl](#):
>
> Isnt this a permissions issue?

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 October 2020 22:31 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/16 "2020-10-22T22:31:32Z")

</div>

"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.

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [23 October 2020 23:09 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/17 "2020-10-23T23:09:57Z")

</div>

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

> [@dceejay](#):
>
> "cannot lock port"

Tried  
sudo lsof /dev/ttyACM0 while runnings NR and got this.  
 ![bild](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5ee24b37e2a73cf44769b6b94464a80a9ea6e971.png)

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

> **[pi@rpidomoticz:~ $...](https://pastebin.com/kiseMxC9)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [24 October 2020 01:31 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/18 "2020-10-24T01:31:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [24 October 2020 08:49 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/19 "2020-10-24T08:49:58Z")

</div>

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

```auto
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

```

```auto
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

---

<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:** [24 October 2020 09:05 UTC](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586/20 "2020-10-24T09:05:19Z")

</div>

Good stuff.

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

[Next page](https://discourse.nodered.org/t/modbus-rtu-issue-with-usb-rs485-adaptor-cannot-lock-port-on-rpi/34586.md?page=2)
