Python - porta serial

Instalar lib serial

 

Fonte: http://pyserial.sourceforge.net/

 

Instale com o comando

 

easy_install -U pyserial

 

Testando

 

Gravando string na porta

 

import serial

ser = serial.Serial(0)  # abre a ttyS0

print ser.portsrt       # imprime o que abriu  

ser.write("hello")      # escreve hello na serial

ser.close()             # fecha a porta

 

Lendo a porta

 

ser = serial.Serial("/dev/ttyS0", 9600, timeout=1) 

s = ser.read(5)         # le 5 bytes

ser.close()             # fecha a porta

print(s)                # exibe o que leu

 

 

Fonte da matéria

 

http://ferpinheiro.wordpress.com/2011/09/07/usando-python-para-comunicar-com-a-porta-serial/