From 2022efacccf691ec1ed26443bae34a814723a2eb Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Thu, 14 Oct 2021 15:04:12 +0200
Subject: [PATCH] L2SS-392: Support calling OPC-UA methods.

---
 .../tangostationcontrol/clients/opcua_client.py   | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/clients/opcua_client.py b/tangostationcontrol/tangostationcontrol/clients/opcua_client.py
index 145c0ebe6..ceacf690f 100644
--- a/tangostationcontrol/tangostationcontrol/clients/opcua_client.py
+++ b/tangostationcontrol/tangostationcontrol/clients/opcua_client.py
@@ -153,15 +153,18 @@ class OPCUAConnection(AsyncCommClient):
         return read_function, write_function
 
 
-    async def call_method(self, method_path, *args):
-        node = await self.obj.get_child(method_path[:-1])
-        return await node.call_method(method_path[-1], *args)
+    async def _call_method(self, method_path, *args):
+        method_path = self.get_node_path(method_path)
+
+        try:
+            node = await self.obj.get_child(method_path[:-1])
+            result = await node.call_method(method_path[-1], *args)
+        except Exception as e:
+            raise Exception(f"Calling method {method_path} failed") from e
 
 
     def call_method(self, method_path, *args):
-        method_path = self.get_node_path(method_path)
-
-        raise NotImplementedError
+        return asyncio.run_coroutine_threadsafe(self._call_method(method_path, *args), self.event_loop).result()
 
 
 class ProtocolAttribute:
-- 
GitLab