升级小板添加结果返回,升级脚本可以修改波特率

This commit is contained in:
ranchuan
2023-08-18 18:53:09 +08:00
parent 337b970b93
commit 8d779a68f3
9 changed files with 116 additions and 31 deletions

Binary file not shown.

View File

@@ -280,7 +280,8 @@ class protu(QObject):
if(s[0]=="utcp"):
self.ser = utcp(int(s[1]))
else:
self.ser = serial.Serial(port=s[0], baudrate=115200,bytesize=serial.EIGHTBITS,parity=serial.PARITY_NONE,
bsp=int(s[1])
self.ser = serial.Serial(port=s[0], baudrate=bsp,bytesize=serial.EIGHTBITS,parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,timeout=None)
except Exception as e:
print(str(e))
@@ -310,7 +311,7 @@ class protu(QObject):
self.str_err="recv data len too less."
return bytearray()
if(data[0]!=0x59 or data[1]!=0x6d or data[2]!=0x43):
print("frame head not 0x59 0x6d.")
# print("frame head not 0x59 0x6d.")
self.str_err="frame head not 0x59 0x6d."
return bytearray()
length=data[3]|(data[4]<<8)
@@ -331,9 +332,30 @@ class protu(QObject):
self.cmd_no=data[6]|(data[7]<<8)
self.cmd=data[5]
if(self.is_big_data==False):
return data[8:-2]
return bytearray(data[8:-2])
else:
return data[12:-2]
return bytearray(data[12:-2])
# 不带校验的接收函数
def recv_(self):
while(self.ser.is_open):
try:
data=self.ser.read(500)
except Exception as a:
# print("err:",str(a))
print("port closed")
return
if(len(data)>0):
t=self.decode(data)
if(self.str_err=="ok"):
self.recv_data+=t
# print("recv",t.hex(","))
# print(type(self.cmd),type(t),type(self.str_err))
self.recv_signal.emit(self.cmd,t,self.str_err)
# self.send_file_next(self.cmd,t,self.str_err)
# print("sent signal---")
else:
print(data.decode("utf-8"))
# 带帧校验的接收函数
def recv(self):
# self.recv_signal.connect(self.send_file_next)
data=bytearray()
@@ -381,7 +403,7 @@ class protu(QObject):
# print("send:",data.hex(","))
self.ser.write(self.encode(data))
def send_str(self,txt:str):
self.ser.write(txt)
self.ser.write(txt.encode("utf-8"))
def start_recv(self):
self.thread_ = threading.Thread(target=self.recv, args=())
self.thread_.start()

View File

@@ -78,14 +78,15 @@ class updata_dlg(QObject):
self.widget = QWidget()
self.widget.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
self.widget.resize(703, 409)
self.widget.setWindowTitle("批检仪程序升级")
self.widget.setWindowTitle("赋码仪程序升级")
self.file_list_init()
self.save_but_init()
self.cmd_but_init()
self.sstate_but_init()
self.updatas_but_init()
self.com_but_init()
self.save_but_init()
# self.updatas_but_init()
# self.cmd_but_init()
# self.sstate_but_init()
self.com_init()
self.combsp_init()
self.widget.destroyed.connect(self.quit)
self.failed_signal.connect(self.updata_failed)
self.cmd=0
@@ -112,7 +113,7 @@ class updata_dlg(QObject):
def com_but_init(self):
self.com_but = QPushButton(self.widget)
self.com_but.setObjectName(u"com_but")
self.com_but.setGeometry(QRect(450, 10, 93, 28))
self.com_but.setGeometry(QRect(590, 10, 93, 28))
self.com_but.setText("打开端口")
self.com_but.clicked.connect(self.com_but_clicked)
@@ -133,6 +134,14 @@ class updata_dlg(QObject):
self.cmd_but.setText("升级MCU")
self.cmd_but.clicked.connect(self.cmd_but_clicked)
# 初始化升级小板按钮
def updatas_but_init(self):
self.updatas_but = QPushButton(self.widget)
self.updatas_but.setObjectName(u"updatas_but")
self.updatas_but.setGeometry(QRect(590, 100, 93, 28))
self.updatas_but.setText("升级小板")
self.updatas_but.clicked.connect(self.updatas_but_clicked)
# 初始化在线状态按钮
def sstate_but_init(self):
self.sstate_but = QPushButton(self.widget)
@@ -141,19 +150,11 @@ class updata_dlg(QObject):
self.sstate_but.setText("MCU在线状态")
self.sstate_but.clicked.connect(self.sstate_but_clicked)
# 初始化升级小板按钮
def updatas_but_init(self):
self.updatas_but = QPushButton(self.widget)
self.updatas_but.setObjectName(u"updatas_but")
self.updatas_but.setGeometry(QRect(590, 180, 93, 28))
self.updatas_but.setText("升级小板")
self.updatas_but.clicked.connect(self.updatas_but_clicked)
# com口
def com_init(self):
self.com = QComboBox(self.widget)
self.com.setObjectName(u"com")
self.com.setGeometry(QRect(100, 10, 300, 21))
self.com.setGeometry(QRect(85, 10, 300, 25))
self.com.setEditable(True)
self.com.currentIndexChanged.connect(self.com_changed)
self.com.addItem("utcp:7777")
@@ -163,9 +164,22 @@ class updata_dlg(QObject):
self.com.addItem(comport.name+":"+comport.description)
self.com_label = QLabel(self.widget)
self.com_label.setObjectName(u"label")
self.com_label.setGeometry(QRect(30, 10, 72, 15))
self.com_label.setGeometry(QRect(30, 16, 72, 15))
self.com_label.setText("COM口:")
# 选择波特率
def combsp_init(self):
self.combsp = QComboBox(self.widget)
self.combsp.setObjectName(u"combsp")
self.combsp.setGeometry(QRect(470, 10, 80, 25))
self.combsp.setEditable(True)
self.combsp.addItem("115200")
self.combsp.addItem("9600")
self.combsp_label = QLabel(self.widget)
self.combsp_label.setObjectName(u"label")
self.combsp_label.setGeometry(QRect(410, 16, 72, 15))
self.combsp_label.setText("波特率:")
# 显示消息框
def show_msg(self,msg:str):
m=QMessageBox(self.widget)
@@ -261,6 +275,7 @@ class updata_dlg(QObject):
self.port.send(self.cmd,d)
except Exception as e:
print("com not open")
self.show_msg("端口未打开")
del self.handle_
w.close()
return
@@ -301,8 +316,10 @@ class updata_dlg(QObject):
def updatas_but_clicked(self):
print("updatas_but clicked.")
try:
self.port.send_str("updatas 1,2,3,4,5,6,7,8,9,10".encode("utf-8"))
self.port.send_str("updatas 1,2,3,4,5,6,7,8,9,10")
self.show_msg("已发送升级指令,请留意小板升级情况")
except Exception as e:
self.show_msg("命令发送失败")
print("com not open")
print(str(e))
@@ -353,6 +370,10 @@ class updata_dlg(QObject):
def com_thread(self):
self.port=prottcp.protu()
item=self.com.itemText(self.com.currentIndex())
bsp=self.combsp.itemText(self.combsp.currentIndex())
com=item.split(":")[0]
if(com!="utcp"):
item=com+":"+bsp
print("item text:",item)
if(self.port.init(item)==False):
print("init port failed.")