def __init__(self, val: int = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_LogLevel*", val._ptr) if val is None: super().__init__(ffi.new("UA_LogLevel*"), is_pointer) else: super().__init__(ffi.cast("UA_LogLevel", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_MonitoringMode*", val._ptr) if val is None: super().__init__(ffi.new("UA_MonitoringMode*"), is_pointer) else: super().__init__(ffi.cast("UA_MonitoringMode", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_TimestampsToReturn*", val._ptr) if val is None: super().__init__(ffi.new("UA_TimestampsToReturn*"), is_pointer) else: super().__init__(ffi.cast("UA_TimestampsToReturn", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_BrowseDirection*", val._ptr) if val is None: super().__init__(ffi.new("UA_BrowseDirection*"), is_pointer) else: super().__init__(ffi.cast("UA_BrowseDirection", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_DataChangeTrigger*", val._ptr) if val is None: super().__init__(ffi.new("UA_DataChangeTrigger*"), is_pointer) else: super().__init__(ffi.cast("UA_DataChangeTrigger", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_NodeAttributesMask*", val._ptr) if val is None: super().__init__(ffi.new("UA_NodeAttributesMask*"), is_pointer) else: super().__init__(ffi.cast("UA_NodeAttributesMask", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if isinstance(val, UaType): val = ffi.cast("UA_AttributeId*", val._ptr) if val is None: super().__init__(ffi.new("UA_AttributeId*"), is_pointer) else: super().__init__(ffi.cast("UA_AttributeId", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_RedundancySupport*", val._ptr) if val is None: super().__init__(ffi.new("UA_RedundancySupport*"), is_pointer) else: super().__init__(ffi.cast("UA_RedundancySupport", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_SecurityTokenRequestType*", val._ptr) if val is None: super().__init__(ffi.new("UA_SecurityTokenRequestType*"), is_pointer) else: super().__init__(ffi.cast("UA_SecurityTokenRequestType", _val(val)), is_pointer)
def __init__(self, val: Union[int, Void] = None, is_pointer=False): if isinstance(val, UaType): val = ffi.cast("UA_SecureChannelState*", val._ptr) if val is None: super().__init__(ffi.new("UA_SecureChannelState*"), is_pointer) else: super().__init__(ffi.cast("UA_SecureChannelState", _val(val)), is_pointer)
def __init__(self, val: Union[UaType, List] = None, size=None, ua_class=None): c_type = "" if type(val) is list: if ua_class is None: if type(val[0]) is int: c_type = "UA_Int64" ua_class = UaInt64 elif type(val[0]) is float: c_type = "UA_Double" ua_class = UaDouble elif type(val[0]) is str: c_type = "UA_String" ua_class = UaString elif type(val[0]) is bool: c_type = "UA_Boolean" ua_class = UaBoolean elif isinstance(ua_class(), UaType): c_type = _get_c_type(ua_class()._ptr) else: raise AttributeError( "'ua_class' has to be None or a Subclass of UaType.") array = ffi.new(f"{c_type}[]", val) size = len(val) else: if isinstance(ua_class(), UaType): c_type = _get_c_type(ua_class()._ptr) else: raise AttributeError( "'ua_class' has do be None or a subclass of UaType.") if size is None: raise AttributeError( "if 'val' is not a python list 'size' has to be set.") elif isinstance(size, SizeT): size = size._val if isinstance(val, UaType): array = ffi.cast(f"{c_type}[{size}]", val._ptr) elif val is None: array = ffi.new(f"{c_type}[{size}]") else: array = ffi.cast(f"{c_type}[{size}]", val) super().__init__(val=array, is_pointer=True) self._size = size self._ua_type = ua_class self._c_type = c_type
def __init__(self, data=None, val=None, is_pointer=True): if data is not None: val = ffi.new_handle(data) elif val is None: val = ffi.NULL super().__init__(ffi.cast("void*", _ptr(val)), is_pointer)
def __init__(self, val=None, is_pointer=False): if isinstance(val, UaType): val = ffi.cast("UA_ClientConfig*", val._ptr) if val is None: val = ffi.new("UA_ClientConfig*") lib.UA_ClientConfig_setDefault(val) super().__init__(val=val, is_pointer=is_pointer) if not self._null: self._client_context = Void(val=val.clientContext, is_pointer=True) self._logger = UaLogger(val=val.logger, is_pointer=False) self._timeout = UaUInt32(val=val.timeout, is_pointer=False) self._client_description = UaUInt32(val=val.clientDescription, is_pointer=False) self._user_identity_token = UaUserIdentityToken( val=val.userIdentityToken, is_pointer=False) self._security_mode = UaMessageSecurityMode(val=val.securityMode, is_pointer=False) self._security_policy_uri = UaString(val=val.securityPolicyUri, is_pointer=False) self._endpoint = UaEndpointDescription(val=val.endpoint, is_pointer=False) self._user_token_policy = UaUserTokenPolicy( val=val.userTokenPolicy, is_pointer=False) self._secure_channel_life_time = UaUInt32( val=val.secureChannelLifeTime, is_pointer=False) self._requested_session_timeout = UaUInt32( val=val.requestedSessionTimeout, is_pointer=False) self._connectivity_check_interval = UaUInt32( val=val.connectivityCheckInterval, is_pointer=False) self._custom_data_types = UaDataTypeArray(val=val.customDataTypes, is_pointer=True)
def __init__(self, log_level: UaLogLevel = None, val=lib.UA_Log_Stdout, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_Logger*", val._ptr) elif log_level is not None: val = lib.UA_Log_Stdout_withLevel(log_level._val) super().__init__(val=val, is_pointer=is_pointer)
def __init__(self, val=None, is_pointer=False): if type(val) is Void: val = ffi.cast("size_t*", val._ptr) if val is None: super().__init__(ffi.new("size_t*"), is_pointer) else: if is_pointer: super().__init__(val, is_pointer) else: super().__init__(ffi.new("size_t*", _val(val)), is_pointer)
def __init__(self, val: Union[Void, float, List[float]] = None, size: int = None, is_pointer=False): if type(val) is Void: if size is None: val = ffi.cast("UA_Double*", val._ptr) else: val = ffi.cast(f"UA_Double[{size}]", val._ptr) is_pointer = True if val is None: super().__init__(ffi.new("UA_Double*"), is_pointer) else: if type(val) is list: super().__init__(ffi.new("UA_Double[]", val), True) elif is_pointer: super().__init__(val, is_pointer) else: super().__init__(ffi.new("UA_Double*", _val(val)), is_pointer) self._size = size
def __init__(self, val: Union[Void, int, List[int]] = None, is_pointer=False): if isinstance(val, UaType): val = ffi.cast("UA_StatusCode*", val._ptr) if val is None: super().__init__(ffi.new("UA_StatusCode*"), is_pointer) else: if type(val) is list: super().__init__(ffi.new("UA_StatusCode[]", val), True) elif is_pointer: super().__init__(val, is_pointer) else: super().__init__(ffi.new("UA_StatusCode*", _val(val)), is_pointer)
def __init__(self, val=None, is_pointer=False): if isinstance(val, UaType): val = ffi.cast("UA_Double*", val._ptr) if val is None: super().__init__(ffi.new("UA_Double*"), is_pointer) else: if type(val) is list: super().__init__(ffi.new("UA_Double[]", val), True) elif is_pointer: super().__init__(val, is_pointer) else: super().__init__(ffi.new("UA_Double*", _val(val)), is_pointer)
def __init__(self, p_val: str = "", is_pointer=True, val=None): if type(val) is Void: val = ffi.cast("char[]", val._ptr) p_val = bytes(p_val, "utf-8") if val is None: super().__init__(ffi.new("char[]", p_val), is_pointer) self._p_value = p_val else: super().__init__(val, is_pointer) if self._null: self._p_value = None else: self._p_value = ffi.string(val)
def __init__(self, val: Union[Void, float, List[float]] = None, is_pointer=False): if type(val) is Void: val = ffi.cast("UA_Float*", val._ptr) if val is None: super().__init__(ffi.new("UA_Float*"), is_pointer) else: if type(val) is list: super().__init__(ffi.new("UA_Float[]", val), True) elif is_pointer: super().__init__(val, is_pointer) else: super().__init__(ffi.new("UA_Float*", _val(val)), is_pointer)
def _ptr(val, c_type=""): if c_type == "": c_type = str(val).split("'")[1] c_type = re.sub(r"[^A-Za-z1-9_ ]", "", c_type, re.ASCII).strip() if _is_null(val): return ffi.NULL if "&" in str(val): return ffi.addressof(val) if "*" in str(val) or "[" in str(val): return val else: try: return ffi.cast(c_type + "*", ffi.addressof(val)) except TypeError: return ffi.new(c_type + "*", val)
def __init__(self, val=None, is_pointer=False): if val is None: val = ffi.new("UA_NetworkStatistics*") if isinstance(val, UaType): val = ffi.cast("UA_NetworkStatistics*", val._ptr) super().__init__(val=val, is_pointer=is_pointer) if not self._null: self._current_connection_count = SizeT( val=val.currentConnectionCount, is_pointer=False) self._cumulated_connection_count = SizeT( val=val.cumulatedConnectionCount, is_pointer=False) self._rejected_connection_count = SizeT( val=val.rejectedConnectionCount, is_pointer=False) self._connection_timeout_count = SizeT( val=val.connectionTimeoutCount, is_pointer=False) self._connection_abort_count = SizeT(val=val.connectionAbortCount, is_pointer=False)
def __init__(self, val=None, is_pointer=False): if val is None: val = ffi.new("UA_SecureChannelStatistics*") if isinstance(val, UaType): val = ffi.cast("UA_SecureChannelStatistics*", val._ptr) super().__init__(val=val, is_pointer=is_pointer) if not self._null: self._current_channel_count = SizeT(val=val.currentChannelCount, is_pointer=False) self._cumulated_channel_count = SizeT( val=val.cumulatedChannelCount, is_pointer=False) self._rejected_channel_count = SizeT(val=val.rejectedChannelCount, is_pointer=False) self._channel_timeout_count = SizeT(val=val.channelTimeoutCount, is_pointer=False) self._channel_abort_count = SizeT(val=val.channelAbortCount, is_pointer=False) self._channel_purge_count = SizeT(val=val.channelPurgeCount, is_pointer=False)
def __init__(self, val: Union[str, Void] = None, is_pointer=False): if isinstance(val, UaType): val = ffi.cast("UA_String*", val._ptr) elif type(val) is str: val = ffi.new("UA_String*", lib.UA_String_fromChars(bytes(val, 'utf-8'))) elif type(val) is bytes: val = ffi.new("UA_String*", lib.UA_String_fromChars(val)) elif type(val) is not None: if not is_pointer: val = ffi.new("UA_String*", val) else: val = ffi.new("UA_String*") super().__init__(val=val, is_pointer=is_pointer) if not self._null: self._length = SizeT(val=val.length, is_pointer=False) self._data = UaByte(val=val.data, is_pointer=True) if _is_null(self._data): self._null = True
import sys sys.path.append("../../../build/open62541") import clientApi from intermediateApi import ffi, lib client = clientApi.UaClient() retval = client.connect(b"opc.tcp://christian-ThinkPad:4840/") # node 1 node1 = ffi.new("UA_NodeId*") node1.namespaceIndex = ffi.cast("UA_UInt16", 1) node1.identifierType = lib.UA_NODEIDTYPE_NUMERIC node1.identifier.numeric = ffi.cast("UA_UInt32", 42) qualified_name = ffi.new("UA_QualifiedName*") qualified_name.namespaceIndex = ffi.cast("UA_UInt16", 1) name = ffi.new("UA_String*", None) name.length = ffi.cast("size_t", 5) name.data = ffi.cast("UA_Byte*", 4) qualified_name.name = name[0] # node 2 node2 = ffi.new("UA_NodeId*") node2.namespaceIndex = ffi.cast("UA_UInt16", 1) node2.identifierType = lib.UA_NODEIDTYPE_NUMERIC node2.identifier.numeric = ffi.cast("UA_UInt32", 42) qualified_name2 = ffi.new("UA_QualifiedName*") qualified_name2.namespaceIndex = ffi.cast("UA_UInt16", 1)
import sys sys.path.append("../../build/open62541") from ua import * from intermediateApi import ffi v = UaVariant() i = UaInt32(42) v.set_scalar(i, UA_TYPES.INT32) v2 = UaVariant() v2.copy(v) v3 = UaVariant() dr = [1.1, 1.2, 1.3, 2.1, 2.2, 2.3, 3.1, 3.2, 3.3] d = UaDouble(dr) x = ffi.cast("UA_Double*", ffi.new("UA_Double[]", dr)) print(x[4]) data = ffi.cast("UA_Double[9]", x) f = ffi.new("UA_Double**", data) f[0][4] = 42.0 print(f[0][4]) v3.set_array(d, SizeT(9), UA_TYPES.DOUBLE) v3.array_dimensions = UaUInt32([3, 3]) v3.array_dimensions_size = SizeT(2) # Using ffi to test if the data is stored correctly print(v3.has_array_type(UA_TYPES.DOUBLE)) print(UaList(v3.data, 9, UaDouble).value)
def _val(val, c_type=""): if not _is_ptr(val): return val if c_type != "": return ffi.cast(c_type + "*", val)[0] return val[0]
def _set_value(self, val): if self._is_pointer: self._value = _ptr(val, "UA_SByte") else: self._value[0] = ffi.cast("UA_SByte", _val(val))
def _set_value(self, val): self._value = ffi.cast("void*", _val(val))
def _set_value(self, val): if self._is_pointer: self._value = _ptr(val, "size_t") else: self._value[0] = ffi.cast("size_t", _val(val))