mamol
mamol

Reputation: 158

python serial [Errno 13] Permission denied: /dev/tty*

I try to open serial port, but cant with permission. But works with sudo.

How i can get permission for serial port?

sas@sas-linuxmint ~ $groups sas
sas : sas adm tty dialout cdrom sudo dip plugdev lpadmin sambashare

This my code:

def get_serial_port():
    ser_devs = [dev for dev in os.listdir('/dev') if dev.startswith('tty')]
    for i in ser_devs:
        port = "/dev/" + i
        try :
            ser = serial.Serial(port, 19200)
            if ser.is_open:
                print("OPEN!!!!!!!!!!!!!!!!!!!!!! {}".format(port))
            ser.close()
        except serial.SerialException as e:
            print(e, port)
    return None

output:

[Errno 13] could not open port /dev/ttyprintk: [Errno 13] Permission denied: '/dev/ttyprintk' /dev/ttyprintk

for all ports.

I tried change mod for port, but it doesn't work too

sudo chmod 766 /dev/ttyS10
sudo chmod -R a+rw /dev/ttyS10
sudo chmod 777 /dev/ttyS10
sudo chmod 666 /dev/ttyS10

Upvotes: 1

Views: 7294

Answers (3)

Dimitrios Bouzoulas
Dimitrios Bouzoulas

Reputation: 31

In my case for ttyACM0 the following worked:

sudo chmod a+rw /dev/ttyACM0

Found here. Something to be kept in mind as mentioned in the source is that every time you unplug and replug the device you will need to re-run the command.

This answer is very late but hopefully will help someone.

Upvotes: 0

Farabi
Farabi

Reputation: 1

I tried using the following command:

sudo gpasswd --add ${USER} dialout

To add dialout to my group but with no luck. The following worked for me: (assuming tty1 is the name)

sudo chmod 666 /dev/tty1

Upvotes: 0

yaumera
yaumera

Reputation: 21

may be 2 years late but, you simply add your user to the tty group eg:

sudo usermod -a -G tty $USER

link

Upvotes: 1

Related Questions