Serial port functions require raised priveleges

Linux specific forum
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Serial port functions require raised priveleges

Post by Baldrick »

Hi, been a long long time since I have done any programming at all now, so a stupid question........ :oops:
I am wanting to do some serial port work but find in Linux it appears I need sudo access or else the device access is just simply denied.
How do I do that from my source so i can run in debug screen?
e.g. from the help file:

Code: Select all

  If OpenSerialPort(0, "/dev/ttyUSB0", 300, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
    Debug "Success"
  Else
    Debug "Failed"
  EndIf
Will just fail the same as if I use GTKterm without sudo priveleges.
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Re: Serial port functions require raised priveleges

Post by Baldrick »

It's ok, just worked out I need to run purebasic its'self as sudo... :oops:

Code: Select all

sudo /home/baldrick/purebasic/compilers/purebasic
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Serial port functions require raised priveleges

Post by Oma »

Hello Baldrick,

you are on Linux :wink:
You shouldn't start PureBasic with sudo!

A way is (during programming work) to add the current user to a group with permission for the serial ports, like 'dialout', similar to this example on Xubuntu.Image

You can query groups with access to a specific port (here USB0) in a terminal with:
ls -l /dev/ttyUSB0

Another way (for the current login) is to give access to specific serial ports for 'others' like this (in terminal):
sudo chmod o+rw /dev/ttyUSB0
or to lock again:
sudo chmod o-rw /dev/ttyUSB0

Regards, Charly
ps: The image will not be available forever.
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Re: Serial port functions require raised priveleges

Post by Baldrick »

Many thanks for this tip Oma! :D

Code: Select all

sudo chmod o+rw /dev/ttyUSB0
has worked, so again thank you.
Much I have to learn about Linux, especially now that I very rarely ever do any programming these years.
Post Reply