优化界面
This commit is contained in:
parent
b7908f278d
commit
a22d6fab7b
@ -198,6 +198,9 @@ class IPConfigDialog(QDialog):
|
||||
form_layout.addRow(QLabel("IP 地址:"), self.ip_input)
|
||||
form_layout.addRow(QLabel("子网掩码:"), self.mask_input)
|
||||
form_layout.addRow(QLabel("网关:"), self.gw_input)
|
||||
self.ip_input.setText("192.168.0.151")
|
||||
self.mask_input.setText("255.255.255.0")
|
||||
self.gw_input.setText("192.168.0.1")
|
||||
|
||||
self.save_btn = QPushButton("保存")
|
||||
self.cancel_btn = QPushButton("取消")
|
||||
@ -298,6 +301,7 @@ class CalibrationDialog(QDialog):
|
||||
self.type_cb = QComboBox()
|
||||
self.type_cb.addItems(["温度", "电压DC", "电压AC"])
|
||||
self.type_cb.currentTextChanged.connect(self.update_voltage_points)
|
||||
self.channel_cb.currentTextChanged.connect(self.update_voltage_points)
|
||||
|
||||
top_layout = QHBoxLayout()
|
||||
top_layout.addWidget(QLabel("通道:"))
|
||||
@ -382,6 +386,18 @@ class CalibrationDialog(QDialog):
|
||||
def initialize_calibration(self):
|
||||
for label in self.value_labels:
|
||||
label.setText("未获取")
|
||||
# 获取通道号和类型索引
|
||||
ch = self.channel_cb.currentIndex() + 1 # 通道1 对应 1
|
||||
group = self.type_cb.currentIndex() # 0=temp, 1=dc, 2=ac
|
||||
print(f"ch:{ch},group:{group}")
|
||||
a = 1
|
||||
b = 0
|
||||
header = bytes([0xAA, 0x55, 0xAA, 0x11, 0x01, 0x00]) # 可根据实际协议修改
|
||||
payload = struct.pack('<BBff', ch, group, a, b)
|
||||
packet = header + payload
|
||||
# 发送给 MCU
|
||||
self.socket.write(packet)
|
||||
self.socket.waitForReadyRead()
|
||||
def get_coe(self):
|
||||
try:
|
||||
self.socket.write(bytes(
|
||||
@ -403,8 +419,6 @@ class CalibrationDialog(QDialog):
|
||||
QMessageBox.warning(self, "错误", "请先获取所有电压点的校准值")
|
||||
return
|
||||
|
||||
|
||||
|
||||
# 非线性最小二乘拟合 y = a*x + b
|
||||
def func(p, x):
|
||||
a, b = p
|
||||
@ -414,8 +428,11 @@ class CalibrationDialog(QDialog):
|
||||
return func(p, x) - y
|
||||
|
||||
p0 = [1, 0]
|
||||
plsq = leastsq(error, p0, args=(np.array(x), np.array(y)))
|
||||
plsq = leastsq(error, p0, args=(np.array(y), np.array(x)))
|
||||
a, b = plsq[0]
|
||||
# import numpy as np
|
||||
#
|
||||
# a, b = np.polyfit(x, y, 1)
|
||||
|
||||
print(f"拟合结果: a = {a:.4f}, b = {b:.4f}")
|
||||
|
||||
@ -577,7 +594,7 @@ class CalibrationDialog(QDialog):
|
||||
print(f"top10_min 去除最大的数据后的平均值2:{mean_min}")
|
||||
pp = mean_max - mean_min
|
||||
if self.type_cb.currentIndex() == 2:
|
||||
self.value_labels[self.type_index].setText(str(pp))
|
||||
self.value_labels[self.type_index].setText(str(round(pp,3)))
|
||||
print(f"pp :{mean_max - mean_min}")
|
||||
|
||||
def closeEvent(self, event):
|
||||
|
@ -184,6 +184,10 @@ class SocketClientApp(QMainWindow):
|
||||
self.get_temp_button.setEnabled(False)
|
||||
self.upgrade_button_sampling.setEnabled(False)
|
||||
self.save_button_csv.setEnabled(False)
|
||||
self.mac_config_button.setEnabled(False)
|
||||
self.ipv4_config_button.setEnabled(False)
|
||||
self.calibration_config_button.setEnabled(False)
|
||||
self.get_version_button.setEnabled(False)
|
||||
self.ip_input.setText("192.168.0.199")
|
||||
self.port_input.setText("12345")
|
||||
|
||||
@ -329,10 +333,14 @@ class SocketClientApp(QMainWindow):
|
||||
|
||||
def connect_to_server(self):
|
||||
#self.process_wave_packet('')
|
||||
ip = self.ip_input.text()
|
||||
port = int(self.port_input.text())
|
||||
self.socket.abort()
|
||||
self.socket.connectToHost(ip, port)
|
||||
if self.connect_button.text() == "断开":
|
||||
self.connect_button.setText("连接")
|
||||
self.socket.disconnectFromHost()
|
||||
elif self.connect_button.text() == "连接":
|
||||
ip = self.ip_input.text()
|
||||
port = int(self.port_input.text())
|
||||
self.socket.abort()
|
||||
self.socket.connectToHost(ip, port)
|
||||
|
||||
def on_socket_connected(self):
|
||||
self.status_bar.showMessage("状态: 连接成功")
|
||||
@ -342,18 +350,28 @@ class SocketClientApp(QMainWindow):
|
||||
self.get_temp_button.setEnabled(True)
|
||||
self.upgrade_button_sampling.setEnabled(True)
|
||||
self.save_button_csv.setEnabled(True)
|
||||
self.mac_config_button.setEnabled(True)
|
||||
self.ipv4_config_button.setEnabled(True)
|
||||
self.calibration_config_button.setEnabled(True)
|
||||
self.get_version_button.setEnabled(True)
|
||||
self.connect_button.setText("断开")
|
||||
|
||||
def on_socket_disconnected(self):
|
||||
print("on_socket_disconnected")
|
||||
self.status_bar.showMessage("状态: 连接断开,正在重连...")
|
||||
self.connect_button.setText("连接")
|
||||
self.status_bar.showMessage("状态: 连接断开")
|
||||
self.get_data_button.setEnabled(False)
|
||||
self.get_data_button2.setEnabled(False)
|
||||
self.upgrade_button.setEnabled(False)
|
||||
self.get_temp_button.setEnabled(False)
|
||||
self.upgrade_button_sampling.setEnabled(False)
|
||||
self.save_button_csv.setEnabled(False)
|
||||
self.current_reconnect_attempts = 0
|
||||
self.reconnect_timer.start(self.reconnect_interval)
|
||||
self.mac_config_button.setEnabled(False)
|
||||
self.ipv4_config_button.setEnabled(False)
|
||||
self.calibration_config_button.setEnabled(False)
|
||||
self.get_version_button.setEnabled(False)
|
||||
# self.current_reconnect_attempts = 0
|
||||
# self.reconnect_timer.start(self.reconnect_interval)
|
||||
|
||||
def on_socket_error(self, error):
|
||||
self.status_bar.showMessage(f"状态: 错误 - {self.socket.errorString()}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user