fix: luaD_throw不应该返回,使用while(1)强制死机
[LuatOS.git] / demo / fota_uart / main.py
blobbc0ddcbc0d242e0f5c69be465c2dd1e470dd017d
1 #!/usr/bin/python3
2 # -*- coding: UTF-8 -*-
4 import os, sys, serial.tools.list_ports, time
7 for item in serial.tools.list_ports.comports():
8 if not item.pid or not item.location :
9 continue
10 if item.vid == 0x19d1 and item.pid == 0x0001 and "x.6" in item.location :
11 print(dir(item))
12 print(item.name)
13 with serial.Serial(item.name, 115200, timeout=1) as ser:
14 while 1:
15 ser.write(b"#FOTA\n")
16 data = ser.read(128)
17 if data and data.startswith(b"#FOTA") :
18 print("设备响应", data)
19 with open("fota_uart.bin", "rb") as f :
20 while 1 :
21 fdata = f.read(256)
22 if not fdata :
23 print("发送完毕,退出")
24 sys.exit(0)
25 print("发送升级包数据", len(fdata))
26 ser.write(fdata)
27 data = ser.read(128)
28 if data :
29 print("设备响应", data)
30 else :
31 print("设备没响应", data)
32 break