diff --git a/app.py b/app.py index 28ba222..bbeedc2 100644 --- a/app.py +++ b/app.py @@ -9,6 +9,8 @@ try: _APP_CFG = yaml.safe_load(open('./cfg.yaml')) or {} except Exception: _APP_CFG = {} + +OPCcon = opcua_connector(_APP_CFG) # Page configuration st.set_page_config( @@ -114,29 +116,10 @@ else: if st.session_state.connection_status != "Disconnected": st.session_state.connection_status = "Disconnected" -def add_log(message): - """No-op logger (logs disabled for minimal UI).""" - return None - -def push_button(OPCcon, btn_name): - """Push a button on the OPC UA server""" - try: - if btn_name == 'INIT': - OPCcon.adapt_access_rights() - add_log(f"🔧 INIT button pressed - Access rights adapted") - else: - OPCcon.press_btn(btn_name) - add_log(f"🔘 {btn_name} button pressed") - return True - except Exception as e: - add_log(f"❌ Error pressing {btn_name} button: {e}") - return False def initialize_connection(): """Initialize OPC UA connection""" try: - OPCcon = opcua_connector(_APP_CFG) - # Connect and check status OPCcon.connect() if OPCcon.check_connection() == 1: @@ -154,16 +137,13 @@ def initialize_connection(): def execute_button_action(button_name): """Execute button action with proper error handling""" - if st.session_state.opcua_connector is None: - add_log("❌ No connection available. Please initialize first.") - return - - # Execute directly instead of threading to avoid race conditions - try: - push_button(st.session_state.opcua_connector, button_name) - except Exception as e: - add_log(f"❌ Critical error executing {button_name}: {e}") - + if button_name == 'INIT': + OPCcon.adapt_access_rights() + add_log(f"🔧 INIT button pressed - Access rights adapted") + else: + OPCcon.press_btn(button_name) + add_log(f"🔘 {button_name} button pressed") + return True # Sidebar with st.sidebar: