I created the following test program:
import serial
porta = '/dev/ttyUSB0'
baud_rate = 9600
try:
Obj_porta = serial.Serial(porta, baud_rate)
valor = Obj_porta.read()
print valor
Obj_porta.close()
except serial.SerialException:
print"ERRO: Verifique se ha algum dispositivo conectado na porta!"
It displays the following error message:
runfile('/home/joannis/.spyder2/.temp.py', wdir=r'/home/joannis/.spyder2')
ERRO: Verifique se ha algum dispositivo conectado na porta!
Always fall into the except, as if there really was nothing at the door. When I try / except, it says it does not have access. (permission denied)
runfile('/home/joannis/.spyder2/.temp.py', wdir=r'/home/joannis/.spyder2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/joannis/.spyder2/.temp.py", line 20, in <module>
Obj_porta = serial.Serial(porta, baud_rate)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 261, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 278, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'
When I manually read through the terminal it works perfectly.