Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created September 25, 2017 09:22
Show Gist options
  • Select an option

  • Save TheSkorm/8f3c315b7faa1db5d033df12df07763a to your computer and use it in GitHub Desktop.

Select an option

Save TheSkorm/8f3c315b7faa1db5d033df12df07763a to your computer and use it in GitHub Desktop.
import serial
import time
import string
failure = "Booting Linux on physical CPU" #this is the string we look for. If we find it we know we need to reset tthe device
ser = serial.Serial('/dev/tty.usbserial-A50285BI',baudrate=115200, bytesize=8, parity='N', stopbits=1, xonxoff=0, rtscts=0, timeout=0.1)
#dtr
def resetDevice(ser):
ser.dtr = False
time.sleep(1)
ser.dtr = True
f = open('/Users/mwheeler/seriallog', 'w')
for key in string.printable:
print "Testing with " + key
data = ""
loops = 0
while (failure not in data):
loops += 1
ser.write(key)
data = ser.readline()
print(data)
if loops > 100: #if it takes more than 100 loops before finding the failure then we might have a winner
message = "Found possible escape - " + key + "\n"
print message
f.write(message)
f.flush()
break
print "Key took - " + str(loops)
resetDevice(ser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment