Created
September 18, 2016 21:47
-
-
Save EnriqueV/7d179a7d91e98f2c3678569c367574ed to your computer and use it in GitHub Desktop.
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 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