add(更新opcua客户端、振捣频率按钮、管片任务数据刷新)
This commit is contained in:
@ -36,7 +36,7 @@ class MainController:
|
||||
|
||||
# opcua客户端
|
||||
self.opc_client = OpcuaUiClient()
|
||||
self._start_opc_client()
|
||||
self.opc_client.start()
|
||||
|
||||
# 连接信号
|
||||
self.__connectSignals()
|
||||
@ -44,10 +44,6 @@ class MainController:
|
||||
def showMainWindow(self):
|
||||
# self.main_window.showFullScreen()
|
||||
self.main_window.show()
|
||||
self.main_window.dispatch_task_widget.set_task_time("task1","15:44 PM")
|
||||
self.main_window.dispatch_task_widget.set_task_time("task2","17:37 PM")
|
||||
self.main_window.segment_task_widget.set_task_time("task1","15:38 PM")
|
||||
self.main_window.segment_task_widget.set_task_time("task2","17:24 PM")
|
||||
|
||||
def _initSubControllers(self):
|
||||
# 右侧视频显示控制模块
|
||||
@ -78,7 +74,9 @@ class MainController:
|
||||
|
||||
self.config_manager.msg_clean_interval_changed.connect(self.onMsgDbCleanIntervalChanged) # 消息清理间隔改变
|
||||
|
||||
self.opc_client.opc_signal.value_changed.connect(self._update_opc_value_to_ui, Qt.QueuedConnection) # opcua服务器值改变
|
||||
self.opc_client.opc_signal.value_changed.connect(self._onOpcValueChanged, Qt.QueuedConnection) # opcua服务器值改变
|
||||
|
||||
self.opc_client.opc_signal.opc_log.connect(self.msg_recorder.normal_record, Qt.QueuedConnection) # opcua客户端日志
|
||||
|
||||
|
||||
def handleMainWindowClose(self):
|
||||
@ -87,10 +85,10 @@ class MainController:
|
||||
|
||||
# 停止系统底部控制器中的线程
|
||||
if hasattr(self, 'bottom_control_controller'):
|
||||
self.bottom_control_controller.stop_threads()
|
||||
self.bottom_control_controller.stop_threads()
|
||||
# 停止opc客户端
|
||||
if hasattr(self, 'opc_client'):
|
||||
self._stop_opc_client()
|
||||
self.opc_client.stop_run()
|
||||
|
||||
def start_msg_database_clean_task(self):
|
||||
"""启动清理消息数据库(messages.db)中过期消息的定时任务"""
|
||||
@ -147,84 +145,20 @@ class MainController:
|
||||
# 用新间隔重新启动清理任务
|
||||
self.start_msg_database_clean_task()
|
||||
|
||||
def _update_opc_value_to_ui(self, node_id, var_name, new_value):
|
||||
def _onOpcValueChanged(self, node_id, var_name, new_value):
|
||||
"""
|
||||
OPCUA值变化时的UI更新函数
|
||||
"""
|
||||
try:
|
||||
if var_name == "upper_weight":
|
||||
# 更新上料斗重量
|
||||
self.hopper_controller.onUpdateUpperHopperWeight(new_value)
|
||||
elif var_name == "lower_weight":
|
||||
# 更新下料斗重量
|
||||
self.hopper_controller.onUpdateLowerHopperWeight(new_value)
|
||||
elif var_name == "upper_volume":
|
||||
# 更新上料斗方量
|
||||
self.hopper_controller.onUpdateUpperHopperVolume(new_value)
|
||||
elif var_name == "production_progress":
|
||||
progress = min(new_value, 100) # 限制为100, 进度为去掉百分号之后的整数
|
||||
self.main_window.arc_progress.setProgress(progress)
|
||||
self.main_window.production_progress.setProgress(progress)
|
||||
elif var_name == "lower_clamp_angle":
|
||||
# 更新下料斗夹爪角度
|
||||
self.hopper_controller.onUpdateLowerClampAngle(new_value)
|
||||
elif var_name == "upper_clamp_status":
|
||||
# 更新上料斗夹爪状态 0表示关闭 1表示打开
|
||||
self.hopper_controller.onUpdateUpperClampStatus(new_value)
|
||||
elif var_name == "upper_hopper_position":
|
||||
# 更新上料斗位置 5表示料斗到位,到达振捣室处 66表示在搅拌楼处
|
||||
self.hopper_controller.onUpdateUpperHopperPosition(new_value)
|
||||
if new_value == UpperHopperPosition.MIXING_TOWER.value:
|
||||
# 到达搅拌楼开启搅拌桨旋转
|
||||
self.main_window.mixer_widget.startBladeMix()
|
||||
else:
|
||||
self.main_window.mixer_widget.stopBladeMix()
|
||||
elif var_name == "update_segment_tasks":
|
||||
need_update = new_value
|
||||
if need_update: # 需要更新管片任务
|
||||
self._update_segment_tasks()
|
||||
|
||||
update_method = getattr(self, f"_update_{var_name}", None)
|
||||
if update_method:
|
||||
update_method(new_value)
|
||||
except Exception as e:
|
||||
print(f"_update_opc_value_to_ui: 界面更新失败: {e}")
|
||||
print(f"_onOpcValueChanged: 界面更新失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def _start_opc_client(self):
|
||||
"""启动OPC UA客户端"""
|
||||
import time
|
||||
self.opc_retry_exit = threading.Event()
|
||||
def opc_worker():
|
||||
# 连接服务器
|
||||
while not self.opc_retry_exit.is_set():
|
||||
if self.opc_client.connect():
|
||||
# 创建订阅
|
||||
self.opc_client.create_multi_subscription(interval=500)
|
||||
break # 连接成功,退出重连
|
||||
time.sleep(2)
|
||||
|
||||
# 启动子线程运行OPCUA逻辑
|
||||
opc_thread = threading.Thread(target=opc_worker, daemon=True)
|
||||
opc_thread.start()
|
||||
|
||||
def _stop_opc_client(self):
|
||||
"""停止OPC UA客户端"""
|
||||
if hasattr(self, 'opc_retry_exit'):
|
||||
self.opc_retry_exit.set()
|
||||
if hasattr(self, 'opc_client') and self.opc_client.connected:
|
||||
self.opc_client.disconnect()
|
||||
|
||||
def _update_segment_tasks(self):
|
||||
"""更新左侧的管片任务"""
|
||||
# 1. 管片信息查询线程
|
||||
query_thread = ArtifactInfoQueryThread()
|
||||
# 2. 主线程更新管片任务UI
|
||||
query_thread.query_finished.connect(self.onUpdateUiByArtifactInfo)
|
||||
# 3. 查询管片信息错误
|
||||
query_thread.query_error.connect(self.onQueryArtifactInfoError)
|
||||
query_thread.start()
|
||||
|
||||
def onUpdateUiByArtifactInfo(self, artifact_list:List[ArtifactInfoModel]):
|
||||
def convert_to_ampm(time_str: str) -> str:
|
||||
def convert_to_ampm(self, time_str: str) -> str:
|
||||
"""时间格式转换: 转换为AM/PM形式"""
|
||||
from datetime import datetime
|
||||
time_formats = [
|
||||
@ -238,16 +172,72 @@ class MainController:
|
||||
except ValueError:
|
||||
continue
|
||||
return "--:--"
|
||||
|
||||
def onUpdateUiByArtifactInfo(self, artifact_list:List[ArtifactInfoModel]):
|
||||
for index, artifact in enumerate(artifact_list, 1):
|
||||
if artifact.MouldCode:
|
||||
self.main_window.segment_task_widget.set_task_id(f"task{index}", artifact.MouldCode) # 模具号
|
||||
if artifact.BetonVolume:
|
||||
self.main_window.segment_task_widget.set_task_volume(f"task{index}", artifact.BetonVolume) # 浇筑方量
|
||||
if artifact.BeginTime:
|
||||
time_str = convert_to_ampm(artifact.BeginTime)
|
||||
time_str = self.convert_to_ampm(artifact.BeginTime)
|
||||
self.main_window.segment_task_widget.set_task_time(f"task{index}", time_str) # 开始时间
|
||||
self.main_window.SetSegmentTaskDetails(f"task{index}", artifact) # 更新管片任务详情
|
||||
# 将opc服务中的 segment_tasks的值复原为 0,以便下次触发管片更新
|
||||
self.opc_client.write_value_by_name("segment_tasks", 0)
|
||||
|
||||
# ======================== OPCUA值更新界面方法 ======================
|
||||
def _update_upper_weight(self, val):
|
||||
# 更新上料斗重量
|
||||
self.hopper_controller.onUpdateUpperHopperWeight(val)
|
||||
|
||||
def _update_lower_weight(self, val):
|
||||
# 更新下料斗重量
|
||||
self.hopper_controller.onUpdateLowerHopperWeight(val)
|
||||
|
||||
def _update_upper_volume(self, val):
|
||||
# 更新上料斗方量
|
||||
self.hopper_controller.onUpdateUpperHopperVolume(val)
|
||||
|
||||
def _update_production_progress(self, val):
|
||||
# 更新生产进度,限制为100, 进度为去掉百分号之后的整数
|
||||
progress = val
|
||||
self.main_window.arc_progress.setProgress(progress)
|
||||
self.main_window.production_progress.setProgress(progress)
|
||||
|
||||
def _update_lower_clamp_angle(self, val):
|
||||
# 更新下料斗夹爪角度
|
||||
self.hopper_controller.onUpdateLowerClampAngle(val)
|
||||
|
||||
def _update_upper_clamp_status(self, val):
|
||||
# 更新上料斗夹爪状态 0表示关闭 1表示打开
|
||||
self.hopper_controller.onUpdateUpperClampStatus(val)
|
||||
|
||||
def _update_upper_hopper_position(self, val):
|
||||
# 更新上料斗位置 5表示料斗到位,到达振捣室处 66表示在搅拌楼处
|
||||
self.hopper_controller.onUpdateUpperHopperPosition(val)
|
||||
if val == UpperHopperPosition.MIXING_TOWER.value:
|
||||
self.main_window.mixer_widget.startBladeMix()
|
||||
else:
|
||||
self.main_window.mixer_widget.stopBladeMix()
|
||||
|
||||
def _update_segment_tasks(self, val):
|
||||
if val: # 需要更新管片任务
|
||||
"""更新左侧的管片任务"""
|
||||
if hasattr(self, "query_thread") and self.query_thread.isRunning():
|
||||
return
|
||||
# 1. 管片信息查询线程
|
||||
self.query_thread = ArtifactInfoQueryThread()
|
||||
# 2. 主线程更新管片任务UI
|
||||
self.query_thread.query_finished.connect(self.onUpdateUiByArtifactInfo)
|
||||
# 3. 查询管片信息错误
|
||||
self.query_thread.query_error.connect(self.onQueryArtifactInfoError)
|
||||
self.query_thread.start()
|
||||
|
||||
def onQueryArtifactInfoError(self, error_msg:str):
|
||||
# 查询管片信息失败预警
|
||||
self.msg_recorder.warning_record(error_msg)
|
||||
|
||||
|
||||
def _update_vibration_frequency(self, val):
|
||||
# 更新振捣频率
|
||||
self.main_window.frequency_button_group.set_selected_frequency(val)
|
||||
Reference in New Issue
Block a user