Created
November 3, 2012 04:51
-
-
Save chepecarlos/4006031 to your computer and use it in GitHub Desktop.
Buscar puertos Seriales
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import serial | |
def EnumeraPuertos(): | |
o= os.popen("ls /dev/tty*") | |
p = o.read() | |
q=p.split('\n') | |
Lista=[] | |
cuenta=0 | |
ser = serial.Serial() | |
ser.baudrate = 9600 | |
for i in range(len(q)): | |
if q[i].startswith("/dev/ttyA") or q[i].startswith("/dev/ttyUSB") or q[i].startswith("/dev/ttyS"): | |
Lista.insert(len(Lista), q[i]) | |
cuenta+=1 | |
if cuenta > 0: | |
for i in range (len(Lista)): | |
ser.port = Lista[i] | |
try: | |
ser.open() | |
#print ser | |
print 'Serial conectado ' + Lista[i] | |
ser.close() | |
except: | |
#print "no puerto activo" | |
pass | |
else: | |
print "no hay puertos seriales..." | |
if __name__=="__main__": | |
EnumeraPuertos() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment