Skip to content

Instantly share code, notes, and snippets.

@EnriqueV
Created September 18, 2016 21:47
Show Gist options
  • Save EnriqueV/7d179a7d91e98f2c3678569c367574ed to your computer and use it in GitHub Desktop.
Save EnriqueV/7d179a7d91e98f2c3678569c367574ed to your computer and use it in GitHub Desktop.
import serial, time
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
timeout=0.5
)
if ser.isOpen():
try:
time.sleep(0.5)
numOfLines = 0
REQUEST = "x2f\x3f\x30\x30\x30\x30\x30\x30\x30\x31\x37\x36\x36\x31\x21\x0d\x0a"
while True:
print("parametro: " + REQUEST)
ser.write(REQUEST)
time.sleep(3)
response = ser.readline()
print("request data: " + response)
numOfLines = numOfLines + 1
if (numOfLines >= 5):
break
ser.close()
except Exception, e1:
print "error...: " + str(e1)
else:
print "no se puede abrir el puerto serial"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment