forked from Bass0315/WioLiteAI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWiFi_Program.py
73 lines (59 loc) · 2.67 KB
/
WiFi_Program.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
65
66
67
import subprocess
import datetime
import os
import time
import shlex
import serial
from serial.tools import list_ports
from time import sleep
#from FileControl import fileOperate
DownloadProgram_commamd = r".\uf2conv\uf2conv.exe -f 0x6db66082 -b 0x070000000 .\WIFIprogramme\WIFIprogramme.ino.bin -o x.uf2"
#Download wifi program
def timeout_command(command, timeout):
"""
call shell-command and either return its output or kill it
if it doesn't normally exit within timeout seconds and return None
"""
# if type(command) == type(''): # Adding these two sentences will cause an error.
# command = shlex.split(command)
global Comunicate
start = datetime.datetime.now()
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
resultcode = process.poll()
while resultcode is None:
now = datetime.datetime.now()
if (now - start).seconds > timeout:
process.kill()
return -1
sleep(0.01)
resultcode = process.poll()
Comunicate = process.communicate()
return resultcode
def displayResult(flag):
if flag == True:
print ("- - - - - - - - - - - - - - - - - - - -")
print ("- -")
print ("- succssed -")
print ("- -")
print ("- - - - - - - - - - - - - - - - - - - -")
else:
print ("- - - - - - - - - - - - - - - - - - - -")
print ("- -")
print ("- failed -")
print ("- -")
print ("- - - - - - - - - - - - - - - - - - - -")
input(" Please press the reset button and the user button at the same time. After releasing the reset button, the red light will be on and the board will enter the download mode.<Enter> ")
#WiFi program download
if timeout_command(DownloadProgram_commamd, 10) == 0:
#print (time.strftime(" %H:%M:%S ", time.localtime()) + "!!!!DEBUG!!!!" + str(Comunicate))
if "NEW.UF2" in str(Comunicate):
print (time.strftime(" %H:%M:%S ", time.localtime()) + "WiFi program download completed")
displayResult(True)
print (time.strftime(" %H:%M:%S ", time.localtime()) + "< Please reset board >")
else:
#print (time.strftime(" %H:%M:%S ", time.localtime()) + " ! DEBUG ! ")
print (time.strftime(" %H:%M:%S ", time.localtime()) + "WiFi program download failed")
displayResult(False)
else:
print (time.strftime(" %H:%M:%S ", time.localtime()) + "WiFi program download failed")
displayResult(False)