update 日志模块初见
This commit is contained in:
@ -28,13 +28,15 @@ class TCPClient:
|
||||
def run(self):
|
||||
while True:
|
||||
time.sleep(0.2)
|
||||
self.connected = self.error_count > 0
|
||||
self.connected = (self.error_count == 0)
|
||||
try:
|
||||
if (self.send_Status() and self.send_Command()):
|
||||
self.error_count = 0
|
||||
except Exception as e:
|
||||
self.error_count += 1
|
||||
|
||||
if self.error_count> 5:
|
||||
print("Error: TCPClient is not connected")
|
||||
self.CreatConnect()
|
||||
|
||||
def send_Command(self):
|
||||
return False
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
[Robot_Feed]
|
||||
IPAddress=192.168.3.5
|
||||
Port=8113
|
||||
Port=503
|
||||
j1_min=-150
|
||||
j1_max=+150
|
||||
j2_min=-150
|
||||
|
||||
13
Util/util_log.py
Normal file
13
Util/util_log.py
Normal file
@ -0,0 +1,13 @@
|
||||
import logging
|
||||
|
||||
|
||||
class QTextEditLogger(logging.Handler):
|
||||
def __init__(self, text_widget):
|
||||
super().__init__()
|
||||
self.widget = text_widget
|
||||
|
||||
def emit(self, record):
|
||||
# 格式化日志信息
|
||||
log_message = self.format(record)
|
||||
# 在主线程中更新 QTextEdit
|
||||
self.widget.append(log_message)
|
||||
24
app.py
24
app.py
@ -1,5 +1,6 @@
|
||||
import configparser
|
||||
import json
|
||||
import logging
|
||||
import queue
|
||||
import sys
|
||||
from multiprocessing import Process
|
||||
@ -14,6 +15,7 @@ from Util.util_ini import writeFeedLine_to_ini
|
||||
import Constant
|
||||
from CU.Command import FeedCommand
|
||||
from CU.Feeding import FeedLine, FeedingConfig, Feeding, FeedStatus
|
||||
from Util.util_log import QTextEditLogger
|
||||
#from Vision.camera_coordinate_dete import Detection
|
||||
from ui_untitled import Ui_MainWindow
|
||||
from COM.COM_Robot import RobotClient
|
||||
@ -37,9 +39,18 @@ class MainWindow(QMainWindow,Ui_MainWindow):
|
||||
self.init_Run()
|
||||
self.init_robot_info()
|
||||
self.init_FeedLine()
|
||||
|
||||
self.start_Runing()
|
||||
self.init_log()
|
||||
|
||||
def init_log(self):
|
||||
|
||||
self.logger_textEdit = logging.getLogger("QTextEditLogger")
|
||||
self.logger_textEdit.setLevel(logging.DEBUG)
|
||||
|
||||
text_edit_handler = QTextEditLogger(self.textEdit_log_info)
|
||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
||||
text_edit_handler.setFormatter(formatter)
|
||||
self.logger_textEdit.addHandler(text_edit_handler)
|
||||
|
||||
def init_UI(self):
|
||||
self.pushButton_num1.clicked.connect(self.send_num_button_click)
|
||||
@ -275,8 +286,6 @@ class MainWindow(QMainWindow,Ui_MainWindow):
|
||||
self.main_threading = Thread(target=self.run)
|
||||
self.robot_connect_threading = Thread(target=self.robotClient.run)
|
||||
self.main_threading.start()
|
||||
|
||||
|
||||
self.robot_connect_threading.start()
|
||||
pass
|
||||
|
||||
@ -366,6 +375,7 @@ class MainWindow(QMainWindow,Ui_MainWindow):
|
||||
self.label_maxNum.setText(self.lineEdit_num.text())
|
||||
|
||||
def send_stack_feedSet_button_click(self,index):
|
||||
self.logger.info("This is an info message")
|
||||
self.stackedWidget_feed.setCurrentIndex(index)
|
||||
|
||||
|
||||
@ -413,6 +423,14 @@ class MainWindow(QMainWindow,Ui_MainWindow):
|
||||
instruction_command.instructions.append(position_instruction)
|
||||
request_command = instruction_command.toString()
|
||||
print(request_command)
|
||||
log_str = f'移动到位置:{"自由路径" if move_type==MoveType.AXIS else "姿势直线"}:' \
|
||||
f'm0:{position_instruction.m0}-' \
|
||||
f'm2:{position_instruction.m1}-' \
|
||||
f'm3:{position_instruction.m2}-' \
|
||||
f'm4:{position_instruction.m3}-' \
|
||||
f'm5:{position_instruction.m4}-' \
|
||||
f'm6:{position_instruction.m5}'
|
||||
self.logger_textEdit.info(log_str)
|
||||
self.robotClient.add_sendQuene(request_command)
|
||||
|
||||
def send_get_safe_position_button_click(self):
|
||||
|
||||
@ -84,7 +84,7 @@ class Ui_MainWindow(object):
|
||||
self.frame_6.setFrameShadow(QFrame.Shadow.Raised)
|
||||
self.label_5 = QLabel(self.frame_6)
|
||||
self.label_5.setObjectName(u"label_5")
|
||||
self.label_5.setGeometry(QRect(10, 10, 481, 261))
|
||||
self.label_5.setGeometry(QRect(10, 10, 481, 201))
|
||||
self.label_5.setStyleSheet(u"\n"
|
||||
"background-image: url(:/bg/Image/robot.png);\n"
|
||||
"background-position:center;\n"
|
||||
@ -493,13 +493,6 @@ class Ui_MainWindow(object):
|
||||
self.label_manual_adjust_accuracy = QLabel(self.frame_7)
|
||||
self.label_manual_adjust_accuracy.setObjectName(u"label_manual_adjust_accuracy")
|
||||
self.label_manual_adjust_accuracy.setGeometry(QRect(50, 13, 53, 15))
|
||||
self.textEdit_log = QTextEdit(self.frame_6)
|
||||
self.textEdit_log.setObjectName(u"textEdit_log")
|
||||
self.textEdit_log.setGeometry(QRect(10, 280, 481, 191))
|
||||
self.textEdit_log.setStyleSheet(u"*{\n"
|
||||
" background-image: url(:/bg/Image/robot.png);\n"
|
||||
" background-color: #E6ECF5;\n"
|
||||
"}")
|
||||
self.comboBox_lineIndex = QComboBox(self.frame_6)
|
||||
self.comboBox_lineIndex.addItem("")
|
||||
self.comboBox_lineIndex.addItem("")
|
||||
@ -805,6 +798,30 @@ class Ui_MainWindow(object):
|
||||
" background-color: red;\n"
|
||||
" color: white;\n"
|
||||
" }")
|
||||
self.tabWidget_2 = QTabWidget(self.frame_6)
|
||||
self.tabWidget_2.setObjectName(u"tabWidget_2")
|
||||
self.tabWidget_2.setGeometry(QRect(10, 220, 491, 251))
|
||||
self.tab_3 = QWidget()
|
||||
self.tab_3.setObjectName(u"tab_3")
|
||||
self.textEdit_log_info = QTextEdit(self.tab_3)
|
||||
self.textEdit_log_info.setObjectName(u"textEdit_log_info")
|
||||
self.textEdit_log_info.setGeometry(QRect(0, 0, 491, 231))
|
||||
self.textEdit_log_info.setStyleSheet(u"*{\n"
|
||||
" background-color: #D3D3D3;\n"
|
||||
"}")
|
||||
self.tabWidget_2.addTab(self.tab_3, "")
|
||||
self.tab_4 = QWidget()
|
||||
self.tab_4.setObjectName(u"tab_4")
|
||||
self.textEdit_log_error = QTextEdit(self.tab_4)
|
||||
self.textEdit_log_error.setObjectName(u"textEdit_log_error")
|
||||
self.textEdit_log_error.setGeometry(QRect(0, 0, 491, 231))
|
||||
self.textEdit_log_error.setStyleSheet(u"*{\n"
|
||||
" color: red;\n"
|
||||
"\n"
|
||||
" background-color: #D3D3D3;\n"
|
||||
"}\n"
|
||||
"")
|
||||
self.tabWidget_2.addTab(self.tab_4, "")
|
||||
self.stackedWidget_feed.addWidget(self.page_6)
|
||||
self.page_7 = QWidget()
|
||||
self.page_7.setObjectName(u"page_7")
|
||||
@ -912,8 +929,9 @@ class Ui_MainWindow(object):
|
||||
self.retranslateUi(MainWindow)
|
||||
|
||||
self.tabWidget.setCurrentIndex(0)
|
||||
self.stackedWidget_feed.setCurrentIndex(1)
|
||||
self.stackedWidget_feed.setCurrentIndex(0)
|
||||
self.stackedWidget_num.setCurrentIndex(0)
|
||||
self.tabWidget_2.setCurrentIndex(0)
|
||||
|
||||
|
||||
QMetaObject.connectSlotsByName(MainWindow)
|
||||
@ -966,15 +984,6 @@ class Ui_MainWindow(object):
|
||||
self.lineEdit_manual_adjust_accuracy.setText(QCoreApplication.translate("MainWindow", u"1", None))
|
||||
self.lineEdit_manual_adjust_accuracy.setPlaceholderText(QCoreApplication.translate("MainWindow", u"0.001-20", None))
|
||||
self.label_manual_adjust_accuracy.setText(QCoreApplication.translate("MainWindow", u"\u8c03\u6574\u95f4\u9694\uff1a", None))
|
||||
self.textEdit_log.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
|
||||
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
|
||||
"p, li { white-space: pre-wrap; }\n"
|
||||
"hr { height: 1px; border-width: 0; }\n"
|
||||
"li.unchecked::marker { content: \"\\2610\"; }\n"
|
||||
"li.checked::marker { content: \"\\2612\"; }\n"
|
||||
"</style></head><body style=\" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">2024-08-06 10:10:10\uff1a\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u3002\u3002\u3002</p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">2024-08-06 11:10:10\uff1a\u79fb\u52a8\u673a\u68b0\u81c2\u81f3\u6240\u793a\u4f4d\u7f6e</p></body></html>", None))
|
||||
self.comboBox_lineIndex.setItemText(0, QCoreApplication.translate("MainWindow", u"1\u53f7\u7ebf", None))
|
||||
self.comboBox_lineIndex.setItemText(1, QCoreApplication.translate("MainWindow", u"\u65b0\u5efa\u7ebf", None))
|
||||
|
||||
@ -999,6 +1008,24 @@ class Ui_MainWindow(object):
|
||||
self.lineEdit_speed.setPlaceholderText(QCoreApplication.translate("MainWindow", u"\u8f93\u5165\u6574\u6570\uff0c\u5207\u52ff\u8d85\u901f", None))
|
||||
self.label_2.setText(QCoreApplication.translate("MainWindow", u"\u5f53\u524d\u81ea\u52a8\u901f\u5ea6\uff1a", None))
|
||||
self.pushButton_speed.setText(QCoreApplication.translate("MainWindow", u"PushButton", None))
|
||||
self.textEdit_log_info.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
|
||||
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
|
||||
"p, li { white-space: pre-wrap; }\n"
|
||||
"hr { height: 1px; border-width: 0; }\n"
|
||||
"li.unchecked::marker { content: \"\\2610\"; }\n"
|
||||
"li.checked::marker { content: \"\\2612\"; }\n"
|
||||
"</style></head><body style=\" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
|
||||
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>", None))
|
||||
self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_3), QCoreApplication.translate("MainWindow", u"\u65e5\u5fd7", None))
|
||||
self.textEdit_log_error.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
|
||||
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
|
||||
"p, li { white-space: pre-wrap; }\n"
|
||||
"hr { height: 1px; border-width: 0; }\n"
|
||||
"li.unchecked::marker { content: \"\\2610\"; }\n"
|
||||
"li.checked::marker { content: \"\\2612\"; }\n"
|
||||
"</style></head><body style=\" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
|
||||
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>", None))
|
||||
self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_4), QCoreApplication.translate("MainWindow", u"\u62a5\u8b66", None))
|
||||
self.pushButton_tableFeedSet_addRow.setText(QCoreApplication.translate("MainWindow", u"\u65b0\u589e\u7ebf", None))
|
||||
self.pushButton_tableFeedSet_deleRow.setText(QCoreApplication.translate("MainWindow", u"\u5220\u9664\u7ebf", None))
|
||||
self.pushButton_tableFeedSet_save.setText(QCoreApplication.translate("MainWindow", u"\u4fdd\u5b58", None))
|
||||
|
||||
107
untitled.ui
107
untitled.ui
@ -125,7 +125,7 @@ border-radius: 10px;</string>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_6">
|
||||
<widget class="QFrame" name="frame_2">
|
||||
@ -171,7 +171,7 @@ border-radius: 10px;</string>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>481</width>
|
||||
<height>261</height>
|
||||
<height>201</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
@ -1162,33 +1162,6 @@ font: 10pt "楷体";
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="textEdit_log">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>280</y>
|
||||
<width>481</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">*{
|
||||
background-image: url(:/bg/Image/robot.png);
|
||||
background-color: #E6ECF5;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
hr { height: 1px; border-width: 0; }
|
||||
li.unchecked::marker { content: "\2610"; }
|
||||
li.checked::marker { content: "\2612"; }
|
||||
</style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2024-08-06 10:10:10:当前正在运行。。。</p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2024-08-06 11:10:10:移动机械臂至所示位置</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="comboBox_lineIndex">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@ -1753,6 +1726,82 @@ font: 10pt "楷体";
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTabWidget" name="tabWidget_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>220</y>
|
||||
<width>491</width>
|
||||
<height>251</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>日志</string>
|
||||
</attribute>
|
||||
<widget class="QTextEdit" name="textEdit_log_info">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>491</width>
|
||||
<height>231</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">*{
|
||||
background-color: #D3D3D3;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
hr { height: 1px; border-width: 0; }
|
||||
li.unchecked::marker { content: "\2610"; }
|
||||
li.checked::marker { content: "\2612"; }
|
||||
</style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
<string>报警</string>
|
||||
</attribute>
|
||||
<widget class="QTextEdit" name="textEdit_log_error">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>491</width>
|
||||
<height>231</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">*{
|
||||
color: red;
|
||||
|
||||
background-color: #D3D3D3;
|
||||
}
|
||||
</string>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
hr { height: 1px; border-width: 0; }
|
||||
li.unchecked::marker { content: "\2610"; }
|
||||
li.checked::marker { content: "\2612"; }
|
||||
</style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
Reference in New Issue
Block a user