代码拉取完成,页面将自动刷新
#!/usr/bin/python
#
# tinycom_sf.py
#
# CMD: python tinycom_sf.py "send_file_path" on/off(1: start rx thread)
# --powered by liuyajun(20200316)
#################################################################
import os,sys
import serial
import threading
import serial
import linecache
from tqdm import tqdm
from pathlib import Path
curpath = sys.path[0];
print("Tinycom-sf>: ###########################################################");
print("Tinycom-sf>: # Tinycom-sf");
print("Tinycom-sf>: #");
print("Tinycom-sf>: # ctrl+c / -ec / -exit: terminate downloading");
print("Tinycom-sf>: ###########################################################");
###
devstr = linecache.getline(curpath + '/tinycomcfg', 1);
devstr = devstr.strip("\n");
dev = Path(devstr);
if not(dev.exists()):
print("\033[0;37;41m\nplz connect the SCI...");
print devstr;
print('\033[0m');
exit();
###
spdstr = linecache.getline(curpath + '/tinycomcfg', 2);
spdstr = spdstr.strip("\n");
SERIAL_COM = serial.Serial(devstr, spdstr, timeout=0.2);
###
#sfstr = linecache.getline(curpath + '/tinycom_sendfile_tmp', 1);
#sfstr = sfstr.strip("\n");
sfstr = Path(sys.argv[1]);
sf = Path(sfstr)
if not(sf.is_file()):
print("\033[0;37;41m\nthe file does not exist!");
print sfstr;
print('\033[0m');
exit();
###
def com_rx():
while True:
rcvstr = SERIAL_COM.readline();
rcvstr = rcvstr.strip("\n");
if len(rcvstr):
print "Tinycom-sf-RX>: ",rcvstr;
###
if sys.argv[2] == "on":
rxthread=threading.Thread(target=com_rx);
rxthread.start();
###
if __name__ == '__main__':
try:
# tinycom_sendfile_tmp
print "Tinycom-sf>: ",devstr,spdstr,sfstr;
frs = open(str(sfstr));
rls = frs.readlines();
print("\033[4;30;47mdownloading...");
pbar = tqdm(total=len(rls));
for i in rls:
SERIAL_COM.write(i);
pbar.update( 1 );
frs.close();
print("\nok!");
print('\033[0m');
if sys.argv[2] == "on":
while True:
cmdstr = raw_input("Tinycom-sf-TX>: ");
cmdstr = cmdstr.strip("\n");
if cmdstr == "-ec":
rxthread._Thread__stop();
break;
if cmdstr == "-exit":
rxthread._Thread__stop();
break;
SERIAL_COM.write(cmdstr);
except:
print('\033[0m');
if sys.argv[2] == "on":
rxthread._Thread__stop();
print "# END-tinycom-sf"
exit();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。