From a866e93ad7b98f8e89015a975b4c61db6116a792 Mon Sep 17 00:00:00 2001 From: ranchuan Date: Wed, 25 Oct 2023 19:06:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=90=8E=E8=B5=8B=E7=A0=81?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E8=BF=94=E5=9B=9E200=E4=B9=9F=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E8=B5=8B=E7=A0=81=E7=BB=93=E6=9E=9C=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=94=B5=E6=9C=BA=E4=B8=8B=E9=99=8D=E6=8C=89=E9=92=AE?= =?UTF-8?q?=20=E6=AF=8F=E6=AC=A1=E8=B5=8B=E7=A0=81=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=87=87=E7=94=A8=E4=B8=8D=E5=90=8C=E7=9A=84=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReadMe.txt | 4 ++++ analysis/data_deal.py | 12 +++++++++++- coder_2ch/coder_main.py | 38 ++++++++++++++++++++++++++++++-------- coder_2ch/coder_params.py | 2 +- daemon/uart_test.py | 21 +++++++++++++++++++++ 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 daemon/uart_test.py diff --git a/ReadMe.txt b/ReadMe.txt index 2d379a3..7b68bc9 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -86,4 +86,8 @@ 分析工具添加导出数据和分析结果html文件 2023.10.22 添加毛刺过滤算法,去除基线漂移算法 +2023.10.25 + 检测后赋码如果返回200也保存赋码结果 + 添加电机下降按钮 + 每次赋码结果采用不同的颜色 diff --git a/analysis/data_deal.py b/analysis/data_deal.py index 3604f2e..bfe11cc 100644 --- a/analysis/data_deal.py +++ b/analysis/data_deal.py @@ -210,4 +210,14 @@ def show_xy(xy_list:list): ax.legend() index+=1 plt.show() -show_xy([(x,y2),(x,y3),(x,y4)]) +# show_xy([(x,y2),(x,y3),(x,y4)]) + + +# def calc_bytes(a,b,c,i,j,k): +# ta=((a&((1<>8,t&0xff]) + +# print(calc_bytes(20,15,13,5,7,4).hex(' ')) \ No newline at end of file diff --git a/coder_2ch/coder_main.py b/coder_2ch/coder_main.py index 1bdef0a..9e6377b 100644 --- a/coder_2ch/coder_main.py +++ b/coder_2ch/coder_main.py @@ -57,9 +57,10 @@ class coder(QObject): self.autoinc_id=False self.autotest_is_open=0 self.uid_length=16 + self.code_list_backcolor=False self.ser=prot.protu() self.widget = QWidget() - self.widget.resize(1500, 800) + self.widget.resize(1500, 900) self.widget.setWindowTitle("批检仪赋码工具") self.com_but_init() self.combsp_init() @@ -76,6 +77,7 @@ class coder(QObject): self.autotest_but_init() self.stop_but_init() self.code_but_init() + self.moterdown_init() self.recv_handler_table_init() self.device_type_init() self.widget.destroyed.connect(self.quit) @@ -189,7 +191,7 @@ class coder(QObject): # 提示信息 def infotext_init(self): self.infotext=QLabel(self.widget) - self.infotext.setGeometry(QRect(30, 765, 1200, 15)) + self.infotext.setGeometry(QRect(30, 865, 1200, 15)) self.infotext.setText("请打开串口以开始赋码") def set_infotext(self,text:str): try: @@ -261,7 +263,15 @@ class coder(QObject): self.code_but.setGeometry(QRect(1250, 330, 93, 28)) self.code_but.clicked.connect(self.code_but_clicked) self.code_but.setText("赋码") - + + # 电机下降 + def moterdown_init(self): + self.moterdown=QPushButton(self.widget) + self.moterdown.setObjectName(u"moteerup") + self.moterdown.setGeometry(QRect(1250, 370, 93, 28)) + self.moterdown.setText("电机下降") + self.moterdown.clicked.connect(self.cmd_moter_down) + # 初始化设备类型选择框 def device_type_init(self): self.device_type_list = QComboBox(self.widget) @@ -281,13 +291,20 @@ class coder(QObject): def code_list_init(self): self.code_list=QTableWidget(self.widget) self.code_list.setObjectName(u"code_list") - self.code_list.setGeometry(QRect(30, 50, 1200, 700)) + self.code_list.setGeometry(QRect(30, 50, 1200, 800)) self.code_list.setColumnCount(6) self.code_list.setHorizontalHeaderLabels(list(["创建时间","通道号","注码结果","管壳码","UID","密码"])) self.code_list.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) # 添加数据 def code_list_add(self,code_line:str): + stat=self.code_list_backcolor + if(stat==True): + bkcolor=QColor() + bkcolor.setRgb(150,150,150,255) + else: + bkcolor=QColor() + bkcolor.setRgb(255,255,255,255) code_strs=code_line.split(",") errcode=int(code_strs[2]) code_strs[2]=cpars.code_errinfo(errcode) @@ -295,8 +312,9 @@ class coder(QObject): self.code_list.insertRow(RowCont) for i in range(6): self.code_list.setItem(RowCont,i,QTableWidgetItem(code_strs[i])) - if(errcode!=0): - self.code_list.item(RowCont,i).setBackground(Qt.GlobalColor.red) + self.code_list.item(RowCont,i).setBackground(bkcolor) + if(errcode!=0): + self.code_list.item(RowCont,2).setBackground(Qt.GlobalColor.red) # 滚动到底部 def code_list_to_bottom(self): self.code_list.scrollToBottom() @@ -580,7 +598,10 @@ class coder(QObject): def cmd_moter_down(self): d=bytearray() d.append(0x03) - self.ser.send(0x40,d) + try: + self.ser.send(0x40,d) + except Exception as e: + self.set_infotext("发送命令失败,是否没有打开串口?") print("moter down.") # 发送赋码指令 @@ -671,7 +692,7 @@ class coder(QObject): ack_i=i[1] if(ack_i!=0): # 接触异常则忽略 - if(ack_i!=3): + if((ack_i!=3) and (ack_i!=200)): ack=False str_start=STR_RED print(str_start+"addr:",i[0],"ack:",ack_i,STR_END) @@ -680,6 +701,7 @@ class coder(QObject): print("\t","psw_code:",i[4]) acks_list.append(str(ack_i)) if(ack==True): + self.code_list_backcolor=not self.code_list_backcolor s="" time=get_time() for i in self.code_list_lock: diff --git a/coder_2ch/coder_params.py b/coder_2ch/coder_params.py index 8ed85b8..48e0286 100644 --- a/coder_2ch/coder_params.py +++ b/coder_2ch/coder_params.py @@ -93,7 +93,7 @@ def code_errinfo(errcode:int): s=i.split(":") if(int(s[0])==errcode): return s[1] - return "未定义的错误码" + return "{d}未定义的错误码".format(d=errcode) # 通道数 diff --git a/daemon/uart_test.py b/daemon/uart_test.py new file mode 100644 index 0000000..e7899fb --- /dev/null +++ b/daemon/uart_test.py @@ -0,0 +1,21 @@ + + +import serial +import serial.tools.list_ports + + + + +ser = serial.Serial(port="/dev/ttySTM1", baudrate=115200,bytesize=serial.EIGHTBITS,parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE,timeout=None) + + + +# file=open("/dev/ttySTM1","wb") +# file.write(b"tVersion.txt=\"V1.04\"") +# file.write(bytearray([0xff,0xff,0xff])) + +ser.write(b"tVersion.txt=\"V1.04\"") +ser.write(bytearray([0xff,0xff,0xff])) + +