3 Star 1 Fork 1

liuliu9520/tinycom

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tinycom_sf.py 2.28 KB
一键复制 编辑 原始数据 按行查看 历史
liuyajun 提交于 2020-03-18 14:03 +08:00 . initial version v1.0 --powered by liuyajun
#!/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();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/liuliu9520/tinycom.git
git@gitee.com:liuliu9520/tinycom.git
liuliu9520
tinycom
tinycom
master

搜索帮助