1. 增加无网络环境使用的逻辑 2. 优化EC指令发送的逻辑
This commit is contained in:
parent
676eb49679
commit
671db5b1db
59
aio.py
59
aio.py
@ -4,7 +4,6 @@ import os
|
||||
import re
|
||||
import sqlite3
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from urllib import request
|
||||
import os.path
|
||||
@ -12,11 +11,10 @@ import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas
|
||||
from matplotlib.widgets import Slider
|
||||
matplotlib.use('QtAgg')
|
||||
|
||||
from PySide6.QtCore import Qt, QThread, Signal, QObject, QTimer
|
||||
from PySide6.QtGui import QTextCursor, QFont, QPixmap, QColor, QBrush, QIcon
|
||||
from PySide6.QtWidgets import QMessageBox, QCheckBox, QSplashScreen, QApplication, QFrame, QLabel, QTreeWidgetItem, QFileDialog, QHeaderView, QDialog, QVBoxLayout, QPlainTextEdit
|
||||
from PySide6.QtWidgets import QMessageBox, QCheckBox, QSplashScreen, QApplication, QLabel, QTreeWidgetItem, QFileDialog, QHeaderView, QDialog, QVBoxLayout, QPlainTextEdit
|
||||
|
||||
import codes.common.clibs as clibs
|
||||
import codes.common.openapi as openapi
|
||||
@ -24,6 +22,7 @@ import codes.ui.main_window as main_window
|
||||
from codes.analysis import brake, current, wavelogger, iso
|
||||
from codes.autotest import do_current, do_brake
|
||||
from codes.durable import factory_test
|
||||
matplotlib.use('QtAgg')
|
||||
|
||||
|
||||
class ContentDialog(QDialog):
|
||||
@ -135,6 +134,10 @@ class MainWindow(main_window.Ui_MainWindow):
|
||||
self.run = RunProg()
|
||||
self.run.moveToThread(self.t)
|
||||
self.run.completed.connect(prog_done)
|
||||
try:
|
||||
self.action.disconnect()
|
||||
except TypeError:
|
||||
pass
|
||||
self.action.connect(self.run.program)
|
||||
self.t.start()
|
||||
self.action.emit((prog, idx, reserved))
|
||||
@ -447,7 +450,7 @@ class MainWindow(main_window.Ui_MainWindow):
|
||||
self.run_program_thread(do_next, -98, self.prog_done_next, None)
|
||||
|
||||
def show_item_content(self, item, column):
|
||||
content = " | ".join([item.text(i) for i in range(self.treew_log.columnCount())])
|
||||
content = "\n".join([item.text(i) for i in range(self.treew_log.columnCount())])
|
||||
dialog = ContentDialog(content, self)
|
||||
dialog.exec()
|
||||
|
||||
@ -880,9 +883,9 @@ class MainWindow(main_window.Ui_MainWindow):
|
||||
return
|
||||
elif content[0].strip().startswith("ctrl"):
|
||||
for item in content[1:]:
|
||||
addr = int(item.split(":")[0].strip())
|
||||
value = int(item.split(":")[1].strip())
|
||||
try:
|
||||
addr = int(item.split(":")[0].strip())
|
||||
value = int(item.split(":")[1].strip())
|
||||
clibs.c_md.c.write_register(addr, value)
|
||||
time.sleep(clibs.INTERVAL/4)
|
||||
except Exception as err:
|
||||
@ -893,20 +896,27 @@ class MainWindow(main_window.Ui_MainWindow):
|
||||
else:
|
||||
QMessageBox.critical(self, "格式错误", "非法的发送内容,自定义发送需参考已有的格式!")
|
||||
|
||||
def prog_done_ec_send(self, results):
|
||||
flag, result, ret, error, idx, cmd = results
|
||||
print(f"res = {results}")
|
||||
if ret[1] == "error":
|
||||
clibs.logger("ERROR", "openapi", f"{ret[0]}", "red")
|
||||
else:
|
||||
self.pte_ec_recv.appendPlainText(str(ret))
|
||||
|
||||
def ec_send(self):
|
||||
def ec_send_thread():
|
||||
return clibs.c_ec.sr_string(cmd)
|
||||
|
||||
if clibs.status["ec"] == 0:
|
||||
QMessageBox.critical(self, "错误", "使用该功能之前,需要先打开 EC 连接!")
|
||||
return
|
||||
if self.pte_ec_send.toPlainText() == "":
|
||||
return
|
||||
|
||||
self.pte_ec_recv.clear()
|
||||
cmd = self.pte_ec_send.toPlainText().strip()
|
||||
try:
|
||||
result = clibs.c_ec.sr_string(cmd)
|
||||
self.pte_ec_recv.appendPlainText(str(result))
|
||||
except Exception as err:
|
||||
self.pte_ec_recv.appendPlainText(f"操作失败:{err}")
|
||||
self.pte_ec_recv.clear()
|
||||
self.run_program_thread(ec_send_thread, -99, self.prog_done_ec_send, cmd)
|
||||
|
||||
def hmi_cb_change(self):
|
||||
cmd = self.cb_hmi_cmd.currentText()
|
||||
@ -1103,17 +1113,20 @@ class SplashScreen(QApplication):
|
||||
self.splash.show()
|
||||
self.splash.showMessage("正在加载资源.....", Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter, Qt.GlobalColor.white)
|
||||
|
||||
# with validation of server version
|
||||
self.t = QThread(self)
|
||||
self.run = InitWork()
|
||||
self.run.moveToThread(self.t)
|
||||
self.run.completed.connect(self.prog_done)
|
||||
self.action.connect(self.run.program)
|
||||
self.t.start()
|
||||
self.action.emit(1)
|
||||
|
||||
# without validation of server version
|
||||
# self.prog_done("true")
|
||||
with open(f"{clibs.PREFIX}/files/version/IS_VALIDATE", mode="r", encoding="utf-8") as f_validate:
|
||||
is_validate = f_validate.read()
|
||||
if is_validate == "1":
|
||||
# with validation of server version
|
||||
self.t = QThread(self)
|
||||
self.run = InitWork()
|
||||
self.run.moveToThread(self.t)
|
||||
self.run.completed.connect(self.prog_done)
|
||||
self.action.connect(self.run.program)
|
||||
self.t.start()
|
||||
self.action.emit(1)
|
||||
else:
|
||||
# without validation of server version
|
||||
self.prog_done("true")
|
||||
|
||||
def prog_done(self, result):
|
||||
if result == "false" or result == "":
|
||||
|
1
assets/files/version/IS_VALIDATE
Normal file
1
assets/files/version/IS_VALIDATE
Normal file
@ -0,0 +1 @@
|
||||
1
|
@ -2,8 +2,6 @@ import os
|
||||
import os.path
|
||||
import threading
|
||||
import sqlite3
|
||||
import time
|
||||
|
||||
from PySide6.QtCore import Signal, QThread
|
||||
|
||||
|
||||
|
@ -1753,7 +1753,7 @@ class ExternalCommunication(QThread):
|
||||
clibs.c_hr.execution("socket.set_params", enable=True, ip="0.0.0.0", port=str(self.port), suffix="\r", type=1)
|
||||
# time.sleep(clibs.INTERVAL*2)
|
||||
self.c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.c.settimeout(clibs.INTERVAL*5)
|
||||
self.c.settimeout(clibs.INTERVAL*3)
|
||||
try:
|
||||
self.c.connect((self.ip, self.port))
|
||||
self.logger("INFO", "openapi", f"ec: 外部通信连接成功...", "green")
|
||||
@ -1782,7 +1782,8 @@ class ExternalCommunication(QThread):
|
||||
try:
|
||||
char = self.c.recv(1).decode(encoding="unicode_escape")
|
||||
except Exception as err:
|
||||
self.logger("ERROR", "openapi", f"ec: 获取请求指令 {directive} 的返回数据超时,需确认指令发送格式以及内容正确!具体报错信息如下 {err}", "red")
|
||||
result = [f"ec: 获取请求指令 {directive} 的返回数据超时,需确认指令发送格式以及内容正确!具体报错信息如下 {err}", "error"]
|
||||
return result
|
||||
result = "".join([result, char])
|
||||
return result
|
||||
|
||||
@ -2033,6 +2034,7 @@ class PreDos(object):
|
||||
self.ssh_port = ssh_port
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.logger = clibs.logger
|
||||
|
||||
def __ssh2server(self):
|
||||
try:
|
||||
@ -2041,8 +2043,7 @@ class PreDos(object):
|
||||
self.__ssh.connect(hostname=self.ip, port=self.ssh_port, username=self.username, password=self.password)
|
||||
self.__sftp = self.__ssh.open_sftp()
|
||||
except Exception as err:
|
||||
print(f"predos: SSH 无法连接到 {self.ip}:{self.ssh_port},需检查网络连通性或者登录信息是否正确 {err}")
|
||||
raise Exception("SshConnFailed")
|
||||
self.logger("ERROR", "openapi", f"predos: SSH 无法连接到 {self.ip}:{self.ssh_port},需检查网络连通性或者登录信息是否正确 {err}", "red")
|
||||
|
||||
def push_prj_to_server(self, prj_file):
|
||||
# prj_file:本地工程完整路径
|
||||
|
88
ui/main.ui
88
ui/main.ui
@ -9,8 +9,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1006</width>
|
||||
<height>568</height>
|
||||
<width>1004</width>
|
||||
<height>563</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -1846,8 +1846,8 @@
|
||||
<slot>curve_draw()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>700</x>
|
||||
<y>144</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>701</x>
|
||||
@ -1862,8 +1862,8 @@
|
||||
<slot>durable_cb_change()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>586</x>
|
||||
<y>142</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>546</x>
|
||||
@ -1878,8 +1878,8 @@
|
||||
<slot>pre_page()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>266</y>
|
||||
<x>408</x>
|
||||
<y>523</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>307</x>
|
||||
@ -1894,8 +1894,8 @@
|
||||
<slot>realtime_page()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>266</y>
|
||||
<x>489</x>
|
||||
<y>523</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>435</x>
|
||||
@ -1910,8 +1910,8 @@
|
||||
<slot>next_page()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>266</y>
|
||||
<x>570</x>
|
||||
<y>523</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>520</x>
|
||||
@ -1926,8 +1926,8 @@
|
||||
<slot>search_keyword()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>266</y>
|
||||
<x>731</x>
|
||||
<y>523</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>688</x>
|
||||
@ -1942,8 +1942,8 @@
|
||||
<slot>search_keyword()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>266</y>
|
||||
<x>837</x>
|
||||
<y>521</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>932</x>
|
||||
@ -1958,7 +1958,7 @@
|
||||
<slot>hmi_cb_change()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>475</x>
|
||||
<x>810</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
@ -1974,7 +1974,7 @@
|
||||
<slot>hmi_send()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>335</x>
|
||||
<x>891</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
@ -1990,8 +1990,8 @@
|
||||
<slot>hmi_page()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>982</x>
|
||||
<y>85</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>744</x>
|
||||
@ -2006,8 +2006,8 @@
|
||||
<slot>md_page()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>982</x>
|
||||
<y>124</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>784</x>
|
||||
@ -2022,8 +2022,8 @@
|
||||
<slot>ec_page()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>982</x>
|
||||
<y>163</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>969</x>
|
||||
@ -2038,8 +2038,8 @@
|
||||
<slot>md_cb_change()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>466</x>
|
||||
<y>80</y>
|
||||
<x>808</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>612</x>
|
||||
@ -2054,8 +2054,8 @@
|
||||
<slot>md_send()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>889</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>795</x>
|
||||
@ -2086,7 +2086,7 @@
|
||||
<slot>hmi_conn()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>335</x>
|
||||
<x>545</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
@ -2102,8 +2102,8 @@
|
||||
<slot>md_conn()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>545</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>398</x>
|
||||
@ -2123,7 +2123,7 @@
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>412</x>
|
||||
<y>-1</y>
|
||||
<y>0</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
@ -2134,12 +2134,12 @@
|
||||
<slot>check_interval()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>637</x>
|
||||
<y>109</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>821</x>
|
||||
<y>-3</y>
|
||||
<y>0</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
@ -2155,7 +2155,7 @@
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>540</x>
|
||||
<y>-2</y>
|
||||
<y>0</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
@ -2166,8 +2166,8 @@
|
||||
<slot>hmi_conn()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>385</x>
|
||||
<y>89</y>
|
||||
<x>464</x>
|
||||
<y>87</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>216</x>
|
||||
@ -2246,11 +2246,11 @@
|
||||
<slot>file_browser()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>985</x>
|
||||
<y>75</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>1004</x>
|
||||
<x>1003</x>
|
||||
<y>56</y>
|
||||
</hint>
|
||||
</hints>
|
||||
@ -2262,11 +2262,11 @@
|
||||
<slot>file_browser()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>326</x>
|
||||
<y>80</y>
|
||||
<x>983</x>
|
||||
<y>76</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>1004</x>
|
||||
<x>1003</x>
|
||||
<y>88</y>
|
||||
</hint>
|
||||
</hints>
|
||||
|
Loading…
x
Reference in New Issue
Block a user