Skip to content

Instantly share code, notes, and snippets.

@chepecarlos
Created November 3, 2012 04:51
Show Gist options
  • Save chepecarlos/4006031 to your computer and use it in GitHub Desktop.
Save chepecarlos/4006031 to your computer and use it in GitHub Desktop.
Buscar puertos Seriales
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