Created
September 28, 2021 06:48
-
-
Save lulf/78198359bb4f7c2ebd9e84e76e44bf75 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 | |
import sys | |
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout = 2) # open first serial port | |
print("Using", ser.portstr) # check which port was really used | |
count = 0 | |
while True: | |
ser.write(b"PING\n") # write a string | |
reply = ser.readline() | |
if reply != b"PING\n": | |
print("UNEXPECTED RESPONSE after", count, "pings", reply) | |
sys.exit(1) | |
count += 1 | |
if count > 1000: | |
print("Verified 1000 pings") | |
count = 0 | |
ser.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment