diff --git a/dao/inspection_dao.py b/dao/inspection_dao.py index 98a64b2..24ffa41 100644 --- a/dao/inspection_dao.py +++ b/dao/inspection_dao.py @@ -863,7 +863,7 @@ class InspectionDAO: """ try: sql = """ - SELECT t1.order_id, CASE WHEN t1.position = 12 THEN 'mzl' ELSE name END AS name, value + SELECT t1.order_id, CASE t1.position WHEN 12 THEN 'mzl' when 2 then 'xj' ELSE name END AS name, value FROM wsbz_inspection_data t1 LEFT JOIN main.wsbz_inspection_config wic ON t1.config_id = wic.id WHERE gc_note = ? AND t1.order_id = ? diff --git a/db/jtDB.db b/db/jtDB.db index 6ce237e..4765c28 100644 Binary files a/db/jtDB.db and b/db/jtDB.db differ diff --git a/from pymodbus.py b/from pymodbus.py index 243e104..b818fa1 100644 --- a/from pymodbus.py +++ b/from pymodbus.py @@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient import time client = ModbusTcpClient('localhost', port=5020) client.connect() -client.write_registers(address=11, values=[8922]) +client.write_registers(address=11, values=[9422]) # client.write_registers(address=3, values=[0]) # time.sleep(2) # client.write_registers(address=0, values=[0]) @@ -13,7 +13,9 @@ client.write_registers(address=11, values=[8922]) # 贴标完成 # client.write_registers(address=24, values=[1]) # client.write_registers(address=2, values=[0]) -# client.write_registers(address=3, values=[0]) +# client.write_registers(address=13, values=[1]) +# time.sleep(2) +client.write_registers(address=13, values=[0]) diff --git a/ui/main_window_ui.py b/ui/main_window_ui.py index 04bfc3f..aa922ff 100644 --- a/ui/main_window_ui.py +++ b/ui/main_window_ui.py @@ -28,7 +28,7 @@ class MainWindowUI(QMainWindow): "线材类型": "xclx", "包装方式": "bzfs", "轴重要求": "zzyq", - "线径公差": "xj", + "线径公差": "xjgc", "备注": "remarks_hb" } diff --git a/widgets/main_window.py b/widgets/main_window.py index a51e45f..ba009b7 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -753,33 +753,17 @@ class MainWindow(MainWindowUI): client = modbus.get_client() try: # 判断当前操作类型(通过检查当前下料信息是否存在) - if self._current_unload_info and self._current_unload_num > 0: - # 下料模式 - 开始下料操作 - # 确保寄存器3(下料启动)设为1,寄存器4已在handle_output中设置了当前层数 - success2 = modbus.write_register_until_success(client, 2, 1) - success3 = modbus.write_register_until_success(client, 3, 1) - - if success2 and success3: - logging.info(f"开始下料操作:当前层数 {self._current_unload_num}/{self._total_unload_num}") - QMessageBox.information(self, "操作提示", f"开始下料操作:当前第{self._current_unload_num}层") - # 填充按钮样式 - # self.fill_start_button_style() - else: - QMessageBox.warning(self, "错误", "开始下料操作失败") - else: - # 上料模式 - 默认操作 - # 写入当前层数到D0寄存器 - success0 = modbus.write_register_until_success(client, 0, self._current_stow_num) - success2 = modbus.write_register_until_success(client, 2, 1) - - if success0 and success2: - self._is_loading_active = True # 标记上料任务已开始 - logging.info(f"开始上料操作:当前层数 {self._current_stow_num}") - # 填充按钮样式 - # self.fill_start_button_style() - else: - QMessageBox.warning(self, "错误", "开始上料操作失败") + # 下料模式 - 开始下料操作 + # 确保寄存器3(下料启动)设为1,寄存器4已在handle_output中设置了当前层数 + success2 = modbus.write_register_until_success(client, 2, 1) + success3 = modbus.write_register_until_success(client, 3, 1) + if success2 and success3: + logging.info(f"开始下料操作:当前层数 {self._current_unload_num}/{self._total_unload_num}") + QMessageBox.information(self, "操作提示", f"开始下料操作:当前第{self._current_unload_num}层") + else: + QMessageBox.warning(self, "错误", "开始下料操作失败") + except Exception as e: logging.error(f"开始操作失败: {str(e)}") QMessageBox.critical(self, "错误", f"开始操作失败: {str(e)}") @@ -2299,12 +2283,10 @@ class MainWindow(MainWindowUI): info['pono'] = self._current_order_code info["dycz"] = info.get("cz") info['qd'] = self._current_gc_qd - - # 4. 添加sc_gch信息 - if hasattr(self, '_current_gc_sc_gch') and self._current_gc_sc_gch: - info['sc_gch'] = self._current_gc_sc_gch - else: - info['sc_gch'] = "" + # 4. 添加sc_gch信息 - 直接使用前端获取到的工程号作为sc_gch + # 避免使用全局的_current_gc_sc_gch,因为可能在称重过程中被其他扫码操作更新 + info['sc_gch'] = gc_note + logging.info(f"使用前端工程号 {gc_note} 作为sc_gch") # 5. 从数据库获取其他信息作为补充 order_others_info = inspection_dao.get_order_others_info(gc_note, self._current_order_code, tray_id) @@ -3184,7 +3166,7 @@ class MainWindow(MainWindowUI): bccd, tccd = inspection_dao.get_xj_range(self._current_order_code) if bccd is not None and tccd is not None: - if float(bccd) - 0.5 <= final_value <= float(tccd) + 0.5: + if float(bccd) - 0.02 <= final_value <= float(tccd) + 0.02: # 使用set_inspection_value保存数据 self.set_inspection_value('xj', xj_config, final_value) logging.info(f"已将稳定的线径值 {final_value:.3f} 保存到工程号 {gc_note} (行 {data_row})") @@ -3974,9 +3956,15 @@ class MainWindow(MainWindowUI): else: new_value = "" - # 智能更新逻辑:如果新值不为空且与当前值不同,则更新;如果新值为空但当前值不为空,则保持当前值 - if new_value and new_value != current_value: - # 有新值且与当前值不同,进行更新 + # 智能更新逻辑:强度字段允许空值覆盖,其他字段空值不覆盖 + should_update = False + if field_name == "强度": # 强度字段允许空值覆盖 + should_update = new_value != current_value + else: # 其他字段:只有新值不为空且与当前值不同时才更新 + should_update = new_value and new_value != current_value + + if should_update: + # 进行更新 try: if isinstance(self.info_values[field_name], QTextEdit): self.info_values[field_name].setPlainText(new_value) @@ -4009,8 +3997,8 @@ class MainWindow(MainWindowUI): # 其他异常也记录并跳过 logging.warning(f"更新控件文本失败,字段: {field_name}, 错误: {str(e)}") continue - elif not new_value and current_value: - # 新值为空但当前值不为空,保持当前值 + elif not new_value and current_value and field_name != "强度": + # 新值为空但当前值不为空,且不是强度字段,保持当前值 logging.debug(f"保持字段 '{field_name}' 的当前值: '{current_value}' (API返回空值)") elif not new_value and not current_value: # 新值和当前值都为空,无需操作