Cannot Connect to Serial Port in Linux (permission denied)

71 views (last 30 days)
Dear guys
I'm using serial port to communicate with a hardware for a HIL simulation. Apparently all was running smooth using Debian 9 and R2020 (not sure a/b version). Now I updated the system to Manjaro and R2021b. No aditional tool is used, just a .m script with serial access.
Since then, serial comms do not work, apparently due to permissions. Which is weird as everything else does work pretty well in system.
This is what happens trying to open serial:
>> hs = serialport("/dev/ttyACM0", 1000000);
Error using serialport (line 116)
Unable to connect to the serialport device at port '/dev/ttyACM0'. Verify that a device is connected
to the port, the port is not in use, and all serialport input arguments and parameter values are
supported by the device.
Additional Information: Unable to create lock file for the port. Permission denied
Error connecting to the serial port.
See related documentation for troubleshooting steps.
  • Device IS connected to the port and listed as available serial
  • The port it NOT in use, since I can open it using Putty, Arduino and a custom interface written in C.
  • serialport call is the same as before, only port name and baud rate parameters are used (1Mbps works in Putty as well)
  • by aditional information given, I tried the following
I've read in forums about permission, so, I first checked this to rule out the problem:
> groups mateusop
wheel audio input lp storage uucp users network power mateusop
> ll /dev/ttyACM0
crw-rw---- 1 root uucp 166, 0 Sep 27 09:55 /dev/ttyACM0
As seen, my user belongs to the uucp group.
I even tried this as suggested in other posts I've read:
> sudo chown mateusop /dev/ttyACM0
> ll /dev/ttyACM0
crw-rw---- 1 mateusop uucp 166, 0 Sep 27 09:55 /dev/ttyACM0
And still matlab fails.
Finally, I'm asking this on matlab forum since every other program works pretty normal:
raw messages shown in ACM0 with putty
"em" is the raw sync message being sent to matlab, seen with Putty.
I think I've ran out of options and ideas.
Thanks for any help.
------- EDIT -----------------------------------------------------------------------------------------------------
I also tried to give permission to ALL:
> sudo chmod 666 /dev/ttyACM0
> ll /dev/ttyACM0
crw-rw-rw- 1 mateusop uucp 166, 0 Sep 27 09:55 /dev/ttyACM0
no sucess too.

Answers (1)

Johannes Andersson
Johannes Andersson on 20 Dec 2022
You can add your user to the dialout group. You have to logout and login before changes take effect.
sudo usermod -a -G dialout <user>
  1 Comment
Vinzenz Brian Gerhard
Vinzenz Brian Gerhard on 31 Jul 2023
I am using Fedora 38, and also experience this problem. I am trying to connect to an Arduino MKR 1010 board using Simulink (Version 10.7, Matlab R2023a) with the Arduino Support Package. I have tried the same setup and same Simulink model on a Windows machine and had no problems there. My user is part of the dialout group, and Matlab is shown to be run by my user as well. Still I get the following error message:
Error:The following error occurred during deployment to your hardware board:
Unable to create lock file for the port. Permission denied
Error connecting to the serial port.
I also have the Arduino IDE v2 installed, which can connect to the Arduino MKR v2 without problems.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!