Compare commits

..

2 Commits

6 changed files with 38 additions and 50 deletions

View File

@ -341,7 +341,7 @@ class GcApi:
# API 配置中的键名
api_key = "get_order_info_by_xpack"
order_dict = {
"xpack": xpack,
"srch_spack": xpack,
"data_corp": corp_id
}
data = {

View File

@ -120,7 +120,7 @@
}
},
"electricity": {
"auto_start": true,
"auto_start": false,
"interval_minutes": 30
}
}

Binary file not shown.

View File

@ -130,7 +130,7 @@ class LoadingDialog(LoadingDialogUI):
main_window = self.parent
if main_window and isinstance(main_window, MainWindow):
# 使用note字段作为订单号已经被修改为mo的值
order_code = order_data.get("note", "")
order_code = order_data.get("mo", "")
logging.info(f"发送订单号到主窗口: {order_code}")
self.order_code_signal.emit(order_code)
@ -238,7 +238,7 @@ class LoadingDialog(LoadingDialogUI):
"""通过托盘号查询订单信息并回显到页面完全仿照on_order_query"""
try:
query_params = {
"xpack": tray_id,
"srch_spack": tray_id,
"corp_id": self.corp_id
}
dialog = OrderQueryDialog(self)

View File

@ -657,8 +657,8 @@ class MainWindow(MainWindowUI):
# 如果用户确认,则执行上料操作
if result == QDialog.Accepted:
# 从对话框中获取订单号和托盘号,并更新到主窗口
order_code = dialog.order_input.text()
tray_code = dialog.tray_input.text()
order_code = dialog.order_input.text().strip()
tray_code = dialog.tray_input.text().strip()
self._current_order_code = order_code
self.tray_edit.setCurrentText(tray_code)
@ -2041,7 +2041,7 @@ class MainWindow(MainWindowUI):
Returns:
float: 重量千克
"""
return round(weight_in_g / 1000.0, 3) # 保留3位小数
return round(weight_in_g / 1000.0, 2) # 保留2位小数
@Slot(int)
def handle_weight_data(self, weight_in_g):
@ -2136,48 +2136,23 @@ class MainWindow(MainWindowUI):
max_retries: 最大重试次数
"""
retry_count = 0
success = False
last_error = None
modbus = ModbusUtils()
client = None
try:
# 获取Modbus客户端现在使用连接池不会每次都创建新连接
client = modbus.get_client()
if not client:
logging.error("无法获取Modbus客户端连接")
return
# 重试机制写入寄存器
while retry_count < max_retries and not success:
try:
# 称重稳定后,给寄存器 D10 为 1 表示已经称重完成
success = modbus.write_register_until_success(client, 10, 1)
if success:
logging.info(f"成功写入D10寄存器值为1表示称重完成")
break
except Exception as e:
last_error = e
retry_count += 1
if retry_count < max_retries:
delay = 0.5 * (2 ** retry_count) # 指数退避
logging.warning(f"写入D10寄存器失败尝试第{retry_count}次重试,等待{delay:.1f}秒: {str(e)}")
time.sleep(delay)
if not success:
logging.error(f"写入D10寄存器失败已尝试{max_retries}次: {str(last_error)}")
return
# 处理稳定重量
# 这里不再写入D10=1全部交由_process_stable_weight处理
self._process_stable_weight(weight_kg)
# 调用打印方法
self._print_weight_label(weight_kg)
# 设置已处理标记和上次处理的重量
self._weight_processed = True
self._last_processed_weight = weight_kg
logging.info(f"已标记重量 {weight_kg}kg 为已处理")
except Exception as e:
logging.error(f"处理稳定重量时发生错误: {str(e)}")
finally:
@ -2245,6 +2220,18 @@ class MainWindow(MainWindowUI):
if not gc_note:
logging.warning("工程号为空")
return
# 保存净重到数据库(毛重-工字轮重量,单位都是千克)
from dao.inspection_dao import InspectionDAO
inspection_dao = InspectionDAO()
gzl_zl_raw = inspection_dao.get_gzl_zl(self._current_order_code)
gzl_zl = 0.0
try:
if gzl_zl_raw:
gzl_zl = float(gzl_zl_raw)
except (ValueError, TypeError):
logging.warning(f"无法将工字轮重量 '{gzl_zl_raw}' 转换为浮点数,将使用默认值 0.0")
net_weight_kg = round(weight_kg - gzl_zl,3)
# 检查轴重要求范围
if "轴重要求" in self.info_values and self.info_values["轴重要求"] is not None:
@ -2258,7 +2245,7 @@ class MainWindow(MainWindowUI):
max_weight = float(parts[1].strip())
# 检查称重值是否在范围内
if weight_kg < min_weight or weight_kg > max_weight:
if net_weight_kg < min_weight or net_weight_kg > max_weight:
# 写入寄存器D10 给值 2 表示重量超出范围
modbus = ModbusUtils()
client = modbus.get_client()
@ -2268,7 +2255,7 @@ class MainWindow(MainWindowUI):
self.warning_msg = QMessageBox(self)
self.warning_msg.setIcon(QMessageBox.Warning)
self.warning_msg.setWindowTitle('重量超出范围')
self.warning_msg.setText(f"称重值 {weight_kg:.3f}kg 不在轴重要求范围内 ({min_weight:.1f} - {max_weight:.1f}kg)")
self.warning_msg.setText(f"称重值 {net_weight_kg:.2f}kg 不在轴重要求范围内 ({min_weight:.1f} - {max_weight:.1f}kg)")
self.warning_msg.setStandardButtons(QMessageBox.NoButton)
self.warning_msg.setModal(False) # 确保非模态
self.warning_msg.setWindowFlags(self.warning_msg.windowFlags() | Qt.WindowStaysOnTopHint) # 置顶显示
@ -2302,6 +2289,12 @@ class MainWindow(MainWindowUI):
return
else:
logging.info(f"称重值 {weight_kg:.3f}kg 在轴重要求范围内 ({min_weight:.1f} - {max_weight:.1f}kg)")
# 只有在范围内才写入D10=1
modbus = ModbusUtils()
client = modbus.get_client()
modbus.write_register_until_success(client, 10, 1)
modbus.close_client(client)
logging.info("已写入D10=1通知PLC称重合格")
else:
logging.debug(f"轴重要求格式不正确: '{zzyq_value}'")
else:
@ -2310,6 +2303,12 @@ class MainWindow(MainWindowUI):
logging.warning(f"解析轴重要求失败,跳过范围检查: {str(e)}")
else:
logging.debug("轴重要求字段不存在或为空,跳过范围检查")
# 没有轴重要求时直接写入D10=1
modbus = ModbusUtils()
client = modbus.get_client()
modbus.write_register_until_success(client, 10, 1)
modbus.close_client(client)
logging.info("无轴重要求已写入D10=1通知PLC称重合格")
# 暂时断开信号连接避免触发cellChanged信号
try:
@ -2326,18 +2325,7 @@ class MainWindow(MainWindowUI):
tray_id = self.tray_edit.currentText()
self.save_inspection_data(self._current_order_code, gc_note, tray_id, 12, 12, str(weight_kg), "pass")
# 保存净重到数据库(毛重-工字轮重量,单位都是千克)
from dao.inspection_dao import InspectionDAO
inspection_dao = InspectionDAO()
gzl_zl_raw = inspection_dao.get_gzl_zl(self._current_order_code)
gzl_zl = 0.0
try:
if gzl_zl_raw:
gzl_zl = float(gzl_zl_raw)
except (ValueError, TypeError):
logging.warning(f"无法将工字轮重量 '{gzl_zl_raw}' 转换为浮点数,将使用默认值 0.0")
net_weight_kg = round(weight_kg - gzl_zl,3)
self.save_inspection_data(self._current_order_code, gc_note, tray_id, 13, 13, str(net_weight_kg), "pass")
# 设置净重单元格(显示千克)
@ -3760,7 +3748,7 @@ class MainWindow(MainWindowUI):
self.update_info_table(order_info)
# 订单号输入框回显 mo 字段
if order_info:
self.order_no_input.setText(order_info.get('mo', ''))
self.order_no_input.setText(order_info.get('mo', '').strip())
def on_report(self):
"""报表按钮点击处理"""

View File

@ -325,7 +325,7 @@ class OrderQueryDialog(OrderQueryDialogUI):
"""通过托盘号查订单数据,返回列表"""
try:
gc_api = GcApi()
response = gc_api.get_order_info_by_xpack(params.get("xpack"), params.get("corp_id"))
response = gc_api.get_order_info_by_xpack(params.get("srch_spack"), params.get("corp_id"))
if response and response.get("status", False):
orders_data = response.get("data", [])
results = []