forked from KR0SIV/SerLCD_Reset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserLCDReset.py
64 lines (50 loc) · 1.66 KB
/
serLCDReset.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import serial
import sys
import glob
import time
def reset():
print('\r\nSending')
print('Please connect your UART tx pin to the rx pin of your SerLCD now')
print('press ctrl-c to stop')
while True:
ser.write('bogus\r'.encode())
def serial_ports():
if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
# this excludes your current terminal "/dev/tty"
ports = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
ports = glob.glob('/dev/tty.*')
else:
raise EnvironmentError('Unsupported platform')
result = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
result.append(port)
except (OSError, serial.SerialException):
pass
return result
print('Welcome to the SerLCD Reset Tool!\r\n')
print('According to the documentation if you send a CR within the few miliseconds during boot you can reset it.\r\n')
print('Please ensure only power and ground are connected, once you start the proceedure connect your UART TX connection to the RX connector on your serLCD package.\r\n\r\n')
print(serial_ports())
comPort = input('\r\nEnter com port number ONLY: ')
try:
ser = serial.Serial(
port='COM' + comPort,
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=1
)
except:
print('invalid com port')
time.sleep(5)
quit()
input('Press Enter to Start Sending')
while True:
reset()