diff --git a/EXEC_INIT.bat b/EXEC_INIT.bat new file mode 100644 index 0000000..c791242 --- /dev/null +++ b/EXEC_INIT.bat @@ -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 diff --git a/RUN_BTN.py b/RUN_BTN.py index cc2955f..485f73c 100644 --- a/RUN_BTN.py +++ b/RUN_BTN.py @@ -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: diff --git a/opcua_connector.py b/opcua_connector.py index 557bb2d..a1565d5 100644 --- a/opcua_connector.py +++ b/opcua_connector.py @@ -31,6 +31,14 @@ class opcua_connector: df = pd.read_csv(filename, delimiter=DELIMITER, header=None) 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. """ @@ -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 + +