feat: 修改Modbus写入值,新增圆形标签checkbox及其逻辑处理,优化线径公差检查提示框
This commit is contained in:
parent
1568d4c5ee
commit
382062239f
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient
|
|||||||
import time
|
import time
|
||||||
client = ModbusTcpClient('localhost', port=5020)
|
client = ModbusTcpClient('localhost', port=5020)
|
||||||
client.connect()
|
client.connect()
|
||||||
client.write_registers(address=11, values=[5962])
|
client.write_registers(address=11, values=[21962])
|
||||||
# client.write_registers(address=3, values=[0])
|
# client.write_registers(address=3, values=[0])
|
||||||
# time.sleep(2)
|
# time.sleep(2)
|
||||||
# client.write_registers(address=0, values=[0])
|
# client.write_registers(address=0, values=[0])
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QMainWindow, QWidget, QLabel, QGridLayout, QVBoxLayout, QHBoxLayout,
|
QMainWindow, QWidget, QLabel, QGridLayout, QVBoxLayout, QHBoxLayout,
|
||||||
QTableWidget, QTableWidgetItem, QHeaderView, QFrame, QSplitter,
|
QTableWidget, QTableWidgetItem, QHeaderView, QFrame, QSplitter,
|
||||||
QPushButton, QLineEdit, QAbstractItemView, QComboBox, QSizePolicy, QTextEdit
|
QPushButton, QLineEdit, QAbstractItemView, QComboBox, QSizePolicy, QTextEdit, QCheckBox
|
||||||
)
|
)
|
||||||
from PySide6.QtGui import QFont, QAction, QBrush, QColor
|
from PySide6.QtGui import QFont, QAction, QBrush, QColor
|
||||||
from PySide6.QtCore import Qt, QDateTime, QTimer
|
from PySide6.QtCore import Qt, QDateTime, QTimer
|
||||||
@ -210,6 +210,12 @@ class MainWindowUI(QMainWindow):
|
|||||||
""")
|
""")
|
||||||
self.order_layout.addWidget(self.virtual_order_button)
|
self.order_layout.addWidget(self.virtual_order_button)
|
||||||
|
|
||||||
|
# 添加圆形标签checkbox
|
||||||
|
self.round_label_checkbox = QCheckBox("圆形标签")
|
||||||
|
self.round_label_checkbox.setFont(QFont("微软雅黑", 10))
|
||||||
|
self.round_label_checkbox.setFixedHeight(30)
|
||||||
|
self.order_layout.addWidget(self.round_label_checkbox)
|
||||||
|
|
||||||
self.order_layout.addStretch() # 添加弹性空间,将组件推到左侧
|
self.order_layout.addStretch() # 添加弹性空间,将组件推到左侧
|
||||||
self.task_layout.addLayout(self.order_layout)
|
self.task_layout.addLayout(self.order_layout)
|
||||||
|
|
||||||
|
|||||||
@ -2470,6 +2470,13 @@ class MainWindow(MainWindowUI):
|
|||||||
logging.info(f"添加订单信息成功: {response.get('data',{})}")
|
logging.info(f"添加订单信息成功: {response.get('data',{})}")
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning(self, f"提示", response.get("message",{}))
|
QMessageBox.warning(self, f"提示", response.get("message",{}))
|
||||||
|
# 新增:如果勾选了圆形标签checkbox,则向寄存器D15写入1
|
||||||
|
if hasattr(self, "round_label_checkbox") and self.round_label_checkbox.isChecked():
|
||||||
|
modbus = ModbusUtils()
|
||||||
|
client = modbus.get_client()
|
||||||
|
modbus.write_register_until_success(client, 15, 1)
|
||||||
|
modbus.close_client(client)
|
||||||
|
logging.info("已通知PLC当前使用圆形标签")
|
||||||
|
|
||||||
# 保存贴标数据到数据库
|
# 保存贴标数据到数据库
|
||||||
self.save_inspection_data(self._current_order_code, gc_note, tray_id, 11, 11, str(axios_num), "pass")
|
self.save_inspection_data(self._current_order_code, gc_note, tray_id, 11, 11, str(axios_num), "pass")
|
||||||
@ -3315,7 +3322,75 @@ class MainWindow(MainWindowUI):
|
|||||||
# 获取托盘号
|
# 获取托盘号
|
||||||
tray_id = self.tray_edit.currentText()
|
tray_id = self.tray_edit.currentText()
|
||||||
|
|
||||||
# 公差校验
|
# 检查线径公差范围 - 基于前端【线径公差】字段
|
||||||
|
if "线径公差" in self.info_values and self.info_values["线径公差"] is not None:
|
||||||
|
try:
|
||||||
|
xjgc_value = self.info_values["线径公差"].text().strip()
|
||||||
|
if xjgc_value and "-" in xjgc_value:
|
||||||
|
# 解析线径公差范围,格式如 "0.157 - 0.163",忽略两边空格后分割
|
||||||
|
parts = xjgc_value.split("-")
|
||||||
|
if len(parts) == 2:
|
||||||
|
min_diameter = float(parts[0].strip())
|
||||||
|
max_diameter = float(parts[1].strip())
|
||||||
|
|
||||||
|
# 检查线径值是否在范围内
|
||||||
|
if final_value < min_diameter or final_value > max_diameter:
|
||||||
|
# 写入寄存器D10 给值 3 表示线径超出范围
|
||||||
|
modbus = ModbusUtils()
|
||||||
|
client = modbus.get_client()
|
||||||
|
modbus.write_register_until_success(client, 10, 3)
|
||||||
|
modbus.close_client(client)
|
||||||
|
# 显示自动关闭的警告提示框
|
||||||
|
self.diameter_warning_msg = QMessageBox(self)
|
||||||
|
self.diameter_warning_msg.setIcon(QMessageBox.Warning)
|
||||||
|
self.diameter_warning_msg.setWindowTitle('线径超出范围')
|
||||||
|
self.diameter_warning_msg.setText(f"线径值 {final_value:.3f}mm 不在线径公差范围内 ({min_diameter:.3f} - {max_diameter:.3f}mm)")
|
||||||
|
self.diameter_warning_msg.setStandardButtons(QMessageBox.NoButton)
|
||||||
|
self.diameter_warning_msg.setModal(False) # 确保非模态
|
||||||
|
self.diameter_warning_msg.setWindowFlags(self.diameter_warning_msg.windowFlags() | Qt.WindowStaysOnTopHint) # 置顶显示
|
||||||
|
|
||||||
|
# 使用 show 而非 exec_ 保持非阻塞
|
||||||
|
self.diameter_warning_msg.show()
|
||||||
|
|
||||||
|
# 强制关闭方法:使用多种定时器策略
|
||||||
|
def force_close_diameter_warning():
|
||||||
|
try:
|
||||||
|
if hasattr(self, 'diameter_warning_msg') and self.diameter_warning_msg:
|
||||||
|
if self.diameter_warning_msg.isVisible():
|
||||||
|
self.diameter_warning_msg.close()
|
||||||
|
self.diameter_warning_msg.deleteLater()
|
||||||
|
logging.debug("线径警告弹框已强制关闭")
|
||||||
|
else:
|
||||||
|
logging.debug("线径警告弹框已不可见,跳过关闭")
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(f"强制关闭线径警告弹框时出错: {str(e)}")
|
||||||
|
finally:
|
||||||
|
# 清理引用
|
||||||
|
if hasattr(self, 'diameter_warning_msg'):
|
||||||
|
delattr(self, 'diameter_warning_msg')
|
||||||
|
|
||||||
|
# 使用多个定时器确保关闭
|
||||||
|
QTimer.singleShot(2000, force_close_diameter_warning) # 2秒后关闭
|
||||||
|
QTimer.singleShot(3000, force_close_diameter_warning) # 3秒后再次尝试
|
||||||
|
|
||||||
|
# 重置测量列表,防止重复触发
|
||||||
|
self._diameter_measurements = []
|
||||||
|
|
||||||
|
# 阻止继续执行,等待用户处理
|
||||||
|
logging.warning(f"线径值 {final_value:.3f}mm 超出线径公差范围,已阻止保存,等待用户处理")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
logging.info(f"线径值 {final_value:.3f}mm 在线径公差范围内 ({min_diameter:.3f} - {max_diameter:.3f}mm)")
|
||||||
|
else:
|
||||||
|
logging.debug(f"线径公差格式不正确: '{xjgc_value}'")
|
||||||
|
else:
|
||||||
|
logging.debug(f"线径公差格式不正确或为空,跳过范围检查: '{xjgc_value}'")
|
||||||
|
except (ValueError, AttributeError) as e:
|
||||||
|
logging.warning(f"解析线径公差失败,跳过范围检查: {str(e)}")
|
||||||
|
else:
|
||||||
|
logging.debug("线径公差字段不存在或为空,跳过范围检查")
|
||||||
|
|
||||||
|
# 原有的数据库公差校验(保留作为备用)
|
||||||
from dao.inspection_dao import InspectionDAO
|
from dao.inspection_dao import InspectionDAO
|
||||||
inspection_dao = InspectionDAO()
|
inspection_dao = InspectionDAO()
|
||||||
bccd, tccd = inspection_dao.get_xj_range(self._current_order_code)
|
bccd, tccd = inspection_dao.get_xj_range(self._current_order_code)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user