20250904_141652_
This commit is contained in:
parent
bacb84b736
commit
a05456e8ad
15
EXEC_INIT.bat
Normal file
15
EXEC_INIT.bat
Normal file
@ -0,0 +1,15 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
:: ---------- USER DEFINE --------------
|
||||
set "venvName=opcua_com"
|
||||
set "scriptPath=RUN_BTN.py"
|
||||
set "arg=-n INIT"
|
||||
:: -------------------------------------
|
||||
|
||||
:: Activate the Conda environment and execute the Python script
|
||||
call conda activate %venvName%
|
||||
python "%scriptPath%" %arg%
|
||||
|
||||
:: Pause at the end of the script
|
||||
#pause
|
||||
@ -34,7 +34,10 @@ def push_btn(OPCcon, btn_name):
|
||||
"""State 2:"""
|
||||
print("---- State 2 ----")
|
||||
try:
|
||||
OPCcon.press_btn(btn_name)
|
||||
if btn_name == 'INIT':
|
||||
OPCcon.adapt_access_rights(OPCcon)
|
||||
else:
|
||||
OPCcon.press_btn(btn_name)
|
||||
print("Press button done.")
|
||||
return 99
|
||||
except Exception as e:
|
||||
|
||||
@ -32,6 +32,14 @@ class opcua_connector:
|
||||
return dict(zip(df.iloc[:, 0], df.iloc[:, 1]))
|
||||
|
||||
|
||||
def adapt_access_rights(self, access_rights="PlcWrite"):
|
||||
'''
|
||||
adapt the userrights
|
||||
'''
|
||||
method_node = self.opcuaclient.get_node("ns=2;s=/Methods/GiveUserAccess")
|
||||
object_node = self.opcuaclient.get_node("ns=2;s=/Methods")
|
||||
object_node.call_method(method_node, self.config['cred']["robot"]["username"], access_rights)
|
||||
|
||||
def _get_opcua_data(self, var_list):
|
||||
""" 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]
|
||||
@ -42,3 +50,5 @@ def _sent_opcua_data_impuls(self, var):
|
||||
node.set_value(1) # Set node to 1
|
||||
# time.sleep(1) # Wait for 1 second
|
||||
# node.set_value(0) # Set node back to 0
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user