forked from rsta2/circle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreboottool.py
41 lines (34 loc) · 853 Bytes
/
reboottool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import serial
import sys
import time
try:
magicstring = ' '.join(sys.argv[1:2])
serialport = ' '.join(sys.argv[2:3])
serialbaud = int(' '.join(sys.argv[3:]))
except Exception:
print("Usage: python reboottool.py MAGICSTRING SERIALPORT BAUDRATE")
exit()
try:
ser = serial.Serial(
port=serialport,
baudrate=serialbaud,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
except Exception:
print("ERROR: Serial Port " + serialport + " busy or inexistent!")
exit()
print("Sending \"" + magicstring + "\" with baudrate of "+ str(serialbaud) + "...")
sys.stdout.flush()
try:
ser.write(magicstring)
except Exception:
print("ERROR: Serial port disconnected. Check connections!")
ser.close()
exit()
print("Waiting for reboot...");
sys.stdout.flush()
time.sleep(4)
print("Completed!")
ser.close()