v1.0 HF1
This commit is contained in:
parent
27734995b6
commit
512b5714d1
8
EXEC.bat
Normal file
8
EXEC.bat
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
@echo off
|
||||||
|
cd /d %~dp0
|
||||||
|
echo Starting OPC UA Robot Control Dashboard...
|
||||||
|
echo.
|
||||||
|
|
||||||
|
REM Use conda run instead of activate (more reliable)
|
||||||
|
conda run -n opcua_com streamlit run app.py --server.port 8505
|
||||||
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
@echo off
|
|
||||||
cd /d %~dp0
|
|
||||||
echo Starting OPC UA Robot Control Dashboard...
|
|
||||||
echo.
|
|
||||||
|
|
||||||
REM Check if conda is available
|
|
||||||
where conda >nul 2>nul
|
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
|
||||||
echo ERROR: Conda is not installed or not in PATH
|
|
||||||
echo Please install Anaconda or Miniconda first
|
|
||||||
pause
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
echo Setting up conda environment...
|
|
||||||
|
|
||||||
REM Try to create environment, if it exists, update it
|
|
||||||
conda env create -f environment.yml 2>nul
|
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
|
||||||
echo Environment already exists, updating...
|
|
||||||
conda env update -f environment.yml
|
|
||||||
)
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo Starting Streamlit app on port 8505 using conda run...
|
|
||||||
conda run -n opcua_com --no-capture-output streamlit run app.py --server.port 8505
|
|
||||||
echo.
|
|
||||||
echo Streamlit exited with code %ERRORLEVEL%.
|
|
||||||
pause
|
|
||||||
44
INSTALL.bat
Normal file
44
INSTALL.bat
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
@echo off
|
||||||
|
cd /d %~dp0
|
||||||
|
echo Installing OPC UA Robot Control Dashboard...
|
||||||
|
echo.
|
||||||
|
|
||||||
|
REM Check if conda is available
|
||||||
|
where conda >nul 2>nul
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo ERROR: Conda is not installed or not in PATH
|
||||||
|
echo Please install Anaconda or Miniconda first
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Checking if environment 'opcua_com' exists...
|
||||||
|
|
||||||
|
REM Check if environment exists using conda info --envs
|
||||||
|
conda info --envs | findstr "opcua_com" >nul 2>&1
|
||||||
|
if %ERRORLEVEL% EQU 0 (
|
||||||
|
echo Environment 'opcua_com' found, updating...
|
||||||
|
conda env update -f environment.yml
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo WARNING: Failed to update environment, but continuing...
|
||||||
|
) else (
|
||||||
|
echo Environment updated successfully!
|
||||||
|
)
|
||||||
|
) else (
|
||||||
|
echo Environment 'opcua_com' not found, creating...
|
||||||
|
conda env create -f environment.yml
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo ERROR: Failed to create environment
|
||||||
|
echo Please check the environment.yml file
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
) else (
|
||||||
|
echo Environment created successfully!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Environment 'opcua_com' is ready!
|
||||||
|
echo You can now run EXEC.bat to start the dashboard.
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
46
app.py
46
app.py
@ -103,8 +103,7 @@ def is_opcua_connected(OPCcon) -> bool:
|
|||||||
try:
|
try:
|
||||||
if OPCcon is None:
|
if OPCcon is None:
|
||||||
return False
|
return False
|
||||||
client = OPCcon.opcuaclient
|
return OPCcon.check_connection() == 1
|
||||||
return hasattr(client, 'uaclient') and client.uaclient and getattr(client.uaclient, 'session', None) is not None
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -119,35 +118,6 @@ def add_log(message):
|
|||||||
"""No-op logger (logs disabled for minimal UI)."""
|
"""No-op logger (logs disabled for minimal UI)."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def check_opcua_server(OPCcon):
|
|
||||||
"""Check if OPC UA server is reachable"""
|
|
||||||
try:
|
|
||||||
# Check if already connected
|
|
||||||
if hasattr(OPCcon.opcuaclient, 'uaclient') and OPCcon.opcuaclient.uaclient:
|
|
||||||
add_log("✅ OPC UA server already connected")
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Try to connect
|
|
||||||
OPCcon.opcuaclient.connect()
|
|
||||||
add_log("✅ OPC UA server is reachable")
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
add_log(f"❌ Error connecting to OPC UA server: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def establish_connection(OPCcon):
|
|
||||||
"""Establish connection to OPC UA server"""
|
|
||||||
try:
|
|
||||||
if OPCcon.opcuaclient.uaclient:
|
|
||||||
add_log("✅ OPC UA connection established")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
add_log("❌ Error establishing connection")
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
add_log(f"❌ Error establishing connection: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def push_button(OPCcon, btn_name):
|
def push_button(OPCcon, btn_name):
|
||||||
"""Push a button on the OPC UA server"""
|
"""Push a button on the OPC UA server"""
|
||||||
try:
|
try:
|
||||||
@ -165,13 +135,12 @@ def push_button(OPCcon, btn_name):
|
|||||||
def initialize_connection():
|
def initialize_connection():
|
||||||
"""Initialize OPC UA connection"""
|
"""Initialize OPC UA connection"""
|
||||||
try:
|
try:
|
||||||
config = yaml.safe_load(open('./cfg.yaml'))
|
config = yaml.safe_load(_APP_CFG)
|
||||||
OPCcon = opcua_connector(config)
|
OPCcon = opcua_connector(config)
|
||||||
|
|
||||||
# Check server
|
# Connect and check status
|
||||||
if check_opcua_server(OPCcon):
|
OPCcon.opcuaclient.connect()
|
||||||
# Establish connection
|
if OPCcon.check_connection() == 1:
|
||||||
if establish_connection(OPCcon):
|
|
||||||
st.session_state.opcua_connector = OPCcon
|
st.session_state.opcua_connector = OPCcon
|
||||||
st.session_state.connection_status = "Connected"
|
st.session_state.connection_status = "Connected"
|
||||||
add_log("🎉 Connection initialized successfully")
|
add_log("🎉 Connection initialized successfully")
|
||||||
@ -216,9 +185,8 @@ with st.sidebar:
|
|||||||
st.session_state.opcua_connector.influxclient.close()
|
st.session_state.opcua_connector.influxclient.close()
|
||||||
add_log("📊 InfluxDB connection closed")
|
add_log("📊 InfluxDB connection closed")
|
||||||
|
|
||||||
# Disconnect OPC UA
|
# Disconnect OPC UA using the new method
|
||||||
if hasattr(st.session_state.opcua_connector, 'opcuaclient'):
|
st.session_state.opcua_connector.disconnect()
|
||||||
st.session_state.opcua_connector.opcuaclient.disconnect()
|
|
||||||
add_log("🔌 Disconnected from OPC UA server")
|
add_log("🔌 Disconnected from OPC UA server")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -22,6 +22,33 @@ class opcua_connector:
|
|||||||
self.influx_bucket = config['cred']["influxdb"]["bucket"]
|
self.influx_bucket = config['cred']["influxdb"]["bucket"]
|
||||||
self.varlist_dict = self.read_varlist(config['data']["cfg_varlist"])
|
self.varlist_dict = self.read_varlist(config['data']["cfg_varlist"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def check_connection(self):
|
||||||
|
'''
|
||||||
|
check if the connection is established
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
if self.opcuaclient:
|
||||||
|
print("ROBOT-OPCUA connection established.")
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
print("ROBOT-OPCUA connection not established.")
|
||||||
|
return 0
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ROBOT-OPCUA Error establishing connection")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
'''
|
||||||
|
disconnect from the robot
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
self.opcuaclient.disconnect()
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def press_btn(self, btn_name):
|
def press_btn(self, btn_name):
|
||||||
var = self.varlist_dict[btn_name]
|
var = self.varlist_dict[btn_name]
|
||||||
print(var)
|
print(var)
|
||||||
@ -40,12 +67,12 @@ class opcua_connector:
|
|||||||
object_node = self.opcuaclient.get_node("ns=2;s=/Methods")
|
object_node = self.opcuaclient.get_node("ns=2;s=/Methods")
|
||||||
object_node.call_method(method_node, self.config['cred']["robot"]["username"], access_rights)
|
object_node.call_method(method_node, self.config['cred']["robot"]["username"], access_rights)
|
||||||
|
|
||||||
def _get_opcua_data(self, var_list):
|
def _get_opcua_data(self, var_list):
|
||||||
""" Retrieve OPC UA node values based on the list of variable nodes. """
|
""" Retrieve OPC UA node values based on the list of variable nodes. """
|
||||||
return [self.opcuaclient.get_node(var).get_value() for var in var_list]
|
return [self.opcuaclient.get_node(var).get_value() for var in var_list]
|
||||||
|
|
||||||
|
|
||||||
def _sent_opcua_data_impuls(self, var):
|
def _sent_opcua_data_impuls(self, var):
|
||||||
node = self.opcuaclient.get_node(var)
|
node = self.opcuaclient.get_node(var)
|
||||||
node.set_value(1) # Set node to 1
|
node.set_value(1) # Set node to 1
|
||||||
# time.sleep(1) # Wait for 1 second
|
# time.sleep(1) # Wait for 1 second
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user