Skip to content

Instantly share code, notes, and snippets.

@lulf
Created September 28, 2021 06:48
Show Gist options
  • Save lulf/78198359bb4f7c2ebd9e84e76e44bf75 to your computer and use it in GitHub Desktop.
Save lulf/78198359bb4f7c2ebd9e84e76e44bf75 to your computer and use it in GitHub Desktop.
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