Page 1 of 1

Serial port functions require raised priveleges

Posted: Sat Apr 15, 2017 12:49 am
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.

Re: Serial port functions require raised priveleges

Posted: Sat Apr 15, 2017 1:03 am
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

Re: Serial port functions require raised priveleges

Posted: Mon Apr 17, 2017 2:45 pm
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.

Re: Serial port functions require raised priveleges

Posted: Mon Apr 17, 2017 3:52 pm
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.