Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/02/2013, 18:54
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Bucle infinito

Algo así debería de funcionar.

Código Python:
Ver original
  1. #!/usr/bin/env python
  2. import serial
  3. import time
  4. import sys
  5. import socket
  6.  
  7. def main():
  8.      
  9.     print "Conectando con ARDUINO"
  10.     arduino = serial.Serial('/dev/ttyACM0', 9600)
  11.     time.sleep(2) # waiting the initialization...
  12.  
  13.     server = socket.socket()
  14.     server.bind(("192.168.1.105",6969))
  15.     server.listen(1)
  16.     print "Esperando conexion...."
  17.     socket_cliente, datos_cliente = server.accept()
  18.  
  19.     while True:
  20.         print "Esperando Comando...."
  21.         datos = socket_cliente.recv()
  22.      
  23.         print "Comando Recivido...."
  24.         print "Procesando...."
  25.      
  26.         if(datos == 'H'):  
  27.             print "Encendiendo PIN13"
  28.             arduino.write('H')
  29.         else:
  30.             print "Apagando PIN13"
  31.             arduino.write('L')
  32.      
  33.     print "Cerrando Programa..."
  34.     socket_cliente.close()
  35.     server.close()
  36.     arduino.close()
  37.  
  38. if __name__ == "__main__":
  39.     main()