4from aas_standard_parser.reference_helpers
import construct_id_short_path_from_reference
5from basyx.aas.model
import ModelReference, SubmodelElementCollection
6from opcua
import Client
8from ..core.asset_connector
import IAssetConnector
10logger = logging.getLogger(__name__)
14 """Class to connect to an asset using its AID."""
16 def __init__(self, aid_id: str, interface_smc: SubmodelElementCollection):
17 """Initialize the OPCUAAssetConnector for the given AID ID and interface SMC."""
18 logger.debug(f
"Initializing OPCUAAssetConnector for AID '{aid_id}'")
23 super().
__init__(aid_id, interface_smc)
26 """Connect to the OPC UA server."""
27 logger.info(f
"Connecting to OPC UA Asset for AID '{self._aid_id}'")
32 except Exception
as e:
33 logger.error(f
"Failed to connect to OPC UA server: {e}")
34 raise ConnectionError(f
"Failed to connect to OPC UA server. Error: {e}")
from e
36 async def get_value(self, endpoint_reference: ModelReference) -> str |
None:
37 """Get the value for a specific model reference."""
39 raise ConnectionError(
"AssetConnector is not connected.")
42 raise ConnectionError(
"OPCUA Client not properly initialized.")
44 property_idshort_path = construct_id_short_path_from_reference(endpoint_reference)
48 node = self.
_client.get_node(node_id)
49 value_in_payload = node.get_value()
51 if value_in_payload
is None:
57 value_in_payload = json.dumps(json.loads(value_in_payload)[k])
59 return str(value_in_payload)
Interface for asset connectors.
Class to connect to an asset using its AID.
__init__(self, str aid_id, SubmodelElementCollection interface_smc)
Initialize the OPCUAAssetConnector for the given AID ID and interface SMC.
connect(self)
Connect to the OPC UA server.
str|None get_value(self, ModelReference endpoint_reference)
Get the value for a specific model reference.