提交更新
This commit is contained in:
parent
e19356afc7
commit
87730b1732
@ -1,73 +0,0 @@
|
||||
[Quick_config]
|
||||
button00 = write 0,2024100103|序列号
|
||||
button01 = write 1,65000|激光温度
|
||||
button02 = write 2,1000|K*1000
|
||||
button03 = write 3,0|B*1000
|
||||
button04 = write 4,0|可调电阻
|
||||
button05 = write 5,30|电阻抽头
|
||||
button06 = write 6,0|输出温度
|
||||
button07 = write 7,0|输出激光
|
||||
button08 = write 8,1|输出状态
|
||||
button09 = write 9,0|激光温补
|
||||
button10 = write 10,100|噪声长度
|
||||
button11 = write 11,600|扫描长度
|
||||
button12 = |
|
||||
button13 = write 13,30500|气温校准
|
||||
button14 = write 14,1|滑动开关
|
||||
button15 = write 15,10|滑动标准差
|
||||
button16 = write 16,1|浓度温补
|
||||
button17 = |
|
||||
button18 = |
|
||||
button19 = |
|
||||
pushbuttonquick_00 = write 0,2024100102|序列号
|
||||
pushbuttonquick_01 = write 1,65000|激光温度
|
||||
pushbuttonquick_02 = write 2,1000|K*1000
|
||||
pushbuttonquick_03 = write 3,0|B*1000
|
||||
pushbuttonquick_04 = write 4,0|可调电阻
|
||||
pushbuttonquick_05 = write 5,30|电阻抽头
|
||||
pushbuttonquick_06 = write 6,0|输出温度
|
||||
pushbuttonquick_07 = write 7,0|输出激光
|
||||
pushbuttonquick_08 = write 8,1|输出状态
|
||||
pushbuttonquick_09 = write 9,0|激光温补
|
||||
pushbuttonquick_10 = write 10,100|噪声长度
|
||||
pushbuttonquick_11 = write 11,600|扫描长度
|
||||
pushbuttonquick_12 = |
|
||||
pushbuttonquick_13 = write 13,30500|气温校准
|
||||
pushbuttonquick_14 = write 14,1|滑动开关
|
||||
pushbuttonquick_15 = write 15,10|滑动标准差
|
||||
pushbuttonquick_16 = write 16,1|浓度温补
|
||||
pushbuttonquick_17 = |
|
||||
pushbuttonquick_18 = |
|
||||
pushbuttonquick_19 = |
|
||||
pushbuttonquick_20 = |
|
||||
button20 = |
|
||||
button21 = |
|
||||
button22 = |
|
||||
button23 = |
|
||||
button24 = |
|
||||
button25 = |
|
||||
button26 = |
|
||||
button27 = |
|
||||
button28 = |
|
||||
button29 = |
|
||||
button30 = |
|
||||
button31 = |
|
||||
button32 = |
|
||||
button33 = |
|
||||
button34 = |
|
||||
button35 = |
|
||||
button36 = |
|
||||
button37 = |
|
||||
button38 = |
|
||||
button39 = |
|
||||
button40 = |
|
||||
button41 = |
|
||||
button42 = |
|
||||
button43 = |
|
||||
button44 = |
|
||||
button45 = |
|
||||
button46 = |
|
||||
button47 = |
|
||||
button48 = |
|
||||
button49 = |
|
||||
|
Binary file not shown.
@ -1,4 +1,5 @@
|
||||
[Quick_config]
|
||||
log_time = 1
|
||||
button00 = read 0|序列号
|
||||
button01 = read 1|激光温度
|
||||
button02 = read 2|K*1000
|
||||
@ -38,7 +39,7 @@ button35 = write 15,10|滑动标准差
|
||||
button36 = write 16,1|浓度温补
|
||||
button37 = |
|
||||
button38 = |
|
||||
button39 = |
|
||||
button39 = 01 04 01 2D 00 01 A0 3F|
|
||||
button40 = |
|
||||
button41 = |
|
||||
button42 = |
|
||||
|
@ -23,8 +23,11 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
self.setupUi(self)
|
||||
self.quick_num = 99
|
||||
self.init() #信号和槽
|
||||
self.IniPath = "PyNet.ini"
|
||||
self.IniPath = "PyNet.ini"
|
||||
self.log_time = 10
|
||||
self.CheckCfgIniData() #更改按钮的文字
|
||||
self.log_count = 0
|
||||
self.log_buffer = {} #定义成一个字典,键--文件名,值--对于收到的字符串列表
|
||||
|
||||
# 设置Logo和标题
|
||||
#self.setWindowIcon(QIcon('favicon.ico'))
|
||||
@ -53,18 +56,6 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
#加载快捷指令
|
||||
self.widget_6.hide()
|
||||
#加载快捷指令的按键值
|
||||
|
||||
# self.horizontalLayoutQuick_21 = QtWidgets.QHBoxLayout()
|
||||
# self.horizontalLayoutQuick_21.setObjectName("horizontalLayoutQuick_21")
|
||||
# self.lineEditQuick_21 = QtWidgets.QLineEdit(self.layoutWidget1)
|
||||
# self.lineEditQuick_21.setObjectName("lineEditQuick_21")
|
||||
# self.horizontalLayoutQuick_21.addWidget(self.lineEditQuick_21)
|
||||
# self.pushButtonQuick_21 = QtWidgets.QPushButton(self.layoutWidget1)
|
||||
# self.pushButtonQuick_21.setObjectName("pushButtonQuick_21")
|
||||
# self.horizontalLayoutQuick_21.addWidget(self.pushButtonQuick_21)
|
||||
# self.verticalLayout_8.addLayout(self.horizontalLayoutQuick_21)
|
||||
|
||||
|
||||
|
||||
|
||||
#建立信号与槽
|
||||
@ -178,7 +169,7 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
def data_receive(self):
|
||||
try:
|
||||
recv_data = self.udp_socket.recvfrom(1024) # 1024表示本次接收的最大字节数
|
||||
|
||||
out_s = ''
|
||||
# 打印接收到的数据
|
||||
if self.checkBoxHexReceive.checkState():
|
||||
line_utf8 = recv_data[0].hex()
|
||||
@ -194,27 +185,30 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
self.comboBox_channel.addItem(recv_addr)
|
||||
|
||||
if recv_addr==self.comboBox_channel.currentText() or self.comboBox_channel.currentText()=="ALL":
|
||||
self.textEditReceive.insertPlainText('<' + recv_addr+ '> ' )
|
||||
#self.textEditReceive.insertPlainText('<' + recv_addr+ '> ' )
|
||||
|
||||
if self.checkBoxAddDate.isChecked():
|
||||
nowTime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
|
||||
nowTime = nowTime[:-3]
|
||||
self.textEditReceive.insertPlainText(nowTime + " ")
|
||||
|
||||
#self.textEditReceive.insertPlainText(nowTime + " ")
|
||||
self.add_line_to_textedit(nowTime + " ")
|
||||
# HEX显示数据
|
||||
if self.checkBoxHexReceive.checkState():
|
||||
# line_utf8_bytes = line_utf8.hex() # 编码为 UTF-8 字节串
|
||||
out_s = ''
|
||||
|
||||
# for byte in line_utf8_bytes:
|
||||
# out_s += '{:02X} '.format(byte) # 使用大写字母 X
|
||||
|
||||
out_s = ' '.join(['{:02X}'.format(b) for b in bytes.fromhex(line_utf8)])
|
||||
|
||||
self.textEditReceive.insertPlainText(out_s)
|
||||
self.textEditReceive.insertPlainText('\r\n')
|
||||
# self.textEditReceive.insertPlainText(out_s)
|
||||
# self.textEditReceive.insertPlainText('\r\n')
|
||||
self.add_line_to_textedit('<' + recv_addr+ '> ' + out_s)
|
||||
# ASCII显示数据
|
||||
else:
|
||||
#print("解码前",datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
|
||||
self.textEditReceive.insertPlainText(line_utf8)
|
||||
#self.textEditReceive.insertPlainText(line_utf8)
|
||||
self.add_line_to_textedit('<' + recv_addr+ '> ' + line_utf8)
|
||||
#print("解码数据",datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
|
||||
# 接收换行
|
||||
if self.checkBoxCRLF.isChecked():
|
||||
@ -240,17 +234,25 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
if len(line) ==2:
|
||||
sav_name = line[0] +'_'+ datetime.datetime.now().strftime("%Y-%m-%d")+'.txt'
|
||||
sav_str = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")[:23] +" " +line[1]
|
||||
with open(sav_name, mode='a', newline='',encoding='utf-8', errors='replace') as file:
|
||||
file.write(sav_str)
|
||||
|
||||
else:
|
||||
sav_name = datetime.datetime.now().strftime("%Y-%m-%d")+'.log'
|
||||
if self.checkBoxHexReceive.checkState():
|
||||
sav_str = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")[:23] +" " +out_s +"\r\n"
|
||||
else:
|
||||
sav_str = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")[:23] +" " +line_utf8
|
||||
|
||||
|
||||
|
||||
# 将日志信息添加到缓冲区
|
||||
if sav_name not in self.log_buffer:
|
||||
self.log_buffer[sav_name] = []
|
||||
self.log_buffer[sav_name].append(sav_str)
|
||||
|
||||
# 当缓冲区中的记录达到10条时,写入文件
|
||||
if len(self.log_buffer[sav_name]) >= self.log_time:
|
||||
with open(sav_name, mode='a', newline='',encoding='utf-8', errors='replace') as file:
|
||||
file.write(sav_str)
|
||||
file.writelines(self.log_buffer[sav_name])
|
||||
self.log_buffer[sav_name].clear()
|
||||
|
||||
except socket.error as e:
|
||||
#print(f"Socket error: {e}")
|
||||
@ -294,7 +296,7 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
out_s = ''
|
||||
for i in range(0, len(input_s)):
|
||||
out_s = out_s + '{:02X}'.format(input_s[i]) + ' '
|
||||
|
||||
print(out_s)
|
||||
self.textEditReceive.insertPlainText(out_s)
|
||||
# ASCII接收显示
|
||||
else:
|
||||
@ -375,6 +377,18 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
|
||||
self.data_num_received = 0
|
||||
self.lineEditSendNum.setText(str(self.data_num_received))
|
||||
|
||||
#设置接受区域显示条数
|
||||
def add_line_to_textedit(self, new_line):
|
||||
# 获取当前文本并按行分割
|
||||
current_lines = self.textEditReceive.toPlainText().splitlines()
|
||||
# 添加新的行到列表中
|
||||
current_lines.append(new_line)
|
||||
# 如果行数超过100,则删除最早的行,直到剩下100行
|
||||
if len(current_lines) > 1000:
|
||||
current_lines = current_lines[-1000:] # 只保留最新的100行
|
||||
# 将更新后的行列表转换回字符串并设置为textEdit的内容
|
||||
self.textEditReceive.setPlainText('\n'.join(current_lines))
|
||||
|
||||
#检查是否在comboBox_channel中
|
||||
def is_in_comboBox_channel(self,addr_rece):
|
||||
@ -407,6 +421,7 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
if not os.path.exists(self.IniPath):
|
||||
config = ConfigParser()
|
||||
config.add_section('Quick_config')
|
||||
config.set('Quick_config', 'log_time', '10')
|
||||
for i in range(self.quick_num):
|
||||
idx = f'{i:02}'
|
||||
button_name = f'Button{idx}' # 格式化按钮名称,确保两位数
|
||||
@ -417,7 +432,9 @@ class Pyqt5Net(QtWidgets.QWidget,Ui_UartAssistant):
|
||||
config = ConfigParser()
|
||||
config.read(self.IniPath, encoding='utf-8')
|
||||
try:
|
||||
|
||||
# 创建一个空字典来存储按钮名称和对应的配置
|
||||
self.log_time = int(config.get('Quick_config', 'log_time'))
|
||||
# 循环遍历按钮编号,从0到19
|
||||
for i in range(self.quick_num):
|
||||
idx = f'{i:02}'
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user