0
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!
It always falls on except, as if it really had nothing at the door. When I shoot Try/except, it says it has no 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 works perfectly.
n has how to configure the IDE for it to access as root?
– Joannis
by the way chmod 666 /devttyUSB0 worked. dei a --help I understood the command, I just did not understand why of the 666 but every case thank you very much!
– Joannis
The chmod command is one of the few places where numbers are used in Octal. Each digit is a number from 0 to 7, which in binary is represented by 3 bits ; The first digit controls the permissions of the owner of the file (in this case, the owner is "root"), the second digit contravenes permissions for those in the same group (of users) that the file, and the third digit controls the permissions of all system users. In each of the three digits, the first bit controls access to read, the second to write and the third to run. Thus, "666" says that everyone can read and write in the file.
– jsbueno
got it, thanks!
– Joannis