コード例 #1
0
ファイル: uatypes.py プロジェクト: JonSyuGithub/python-opcua
def pack_uatype(uatype, value):
    if uatype in uatype2struct:
        if value is None:
            value = 0
        return uatype2struct[uatype].pack(value)
    elif uatype == "Null":
        return b''
    elif uatype == "String":
        return pack_string(value)
    elif uatype in ("CharArray", "ByteString", "Custom"):
        return pack_bytes(value)
    elif uatype == "DateTime":
        return pack_datetime(value)
    elif uatype == "LocalizedText":
        if isinstance(value, LocalizedText):
            return value.to_binary()
        else:
            return LocalizedText(value).to_binary()
    elif uatype == "ExtensionObject":
        # dependency loop: classes in uaprotocol_auto use Variant defined in this file,
        # but Variant can contain any object from uaprotocol_auto as ExtensionObject.
        # Using local import to avoid import loop
        from opcua.ua.uaprotocol_auto import extensionobject_to_binary
        return extensionobject_to_binary(value)
    else:
        return value.to_binary()
コード例 #2
0
def pack_uatype(uatype, value):
    if uatype in uatype2struct:
        if value is None:
            value = 0
        return uatype2struct[uatype].pack(value)
    elif uatype == "Null":
        return b''
    elif uatype == "String":
        return pack_string(value)
    elif uatype in ("CharArray", "ByteString", "Custom"):
        return pack_bytes(value)
    elif uatype == "DateTime":
        return pack_datetime(value)
    elif uatype == "LocalizedText":
        if isinstance(value, LocalizedText):
            return value.to_binary()
        else:
            return LocalizedText(value).to_binary()
    elif uatype == "ExtensionObject":
        # dependency loop: classes in uaprotocol_auto use Variant defined in this file,
        # but Variant can contain any object from uaprotocol_auto as ExtensionObject.
        # Using local import to avoid import loop
        from opcua.ua.uaprotocol_auto import extensionobject_to_binary
        return extensionobject_to_binary(value)
    else:
        return value.to_binary()
コード例 #3
0
ファイル: ua_binary.py プロジェクト: glomium/python-opcua
def pack_uatype(vtype, value):
    if hasattr(Primitives, vtype.name):
        return getattr(Primitives, vtype.name).pack(value)
    elif vtype.value > 25:
        return Primitives.Bytes.pack(value)
    elif vtype.name == "ExtensionObject":
        # dependency loop: classes in uaprotocol_auto use Variant defined in this file,
        # but Variant can contain any object from uaprotocol_auto as ExtensionObject.
        # Using local import to avoid import loop
        from opcua.ua.uaprotocol_auto import extensionobject_to_binary
        return extensionobject_to_binary(value)
    else:
        try:
            return value.to_binary()
        except AttributeError:
            raise UaError("{} could not be packed with value {}".format(vtype, value))
コード例 #4
0
ファイル: ua_binary.py プロジェクト: squallySP/python-opcua
def pack_uatype(vtype, value):
    if hasattr(Primitives, vtype.name):
        return getattr(Primitives, vtype.name).pack(value)
    elif vtype.value > 25:
        return Primitives.Bytes.pack(value)
    elif vtype.name == "ExtensionObject":
        # dependency loop: classes in uaprotocol_auto use Variant defined in this file,
        # but Variant can contain any object from uaprotocol_auto as ExtensionObject.
        # Using local import to avoid import loop
        from opcua.ua.uaprotocol_auto import extensionobject_to_binary
        return extensionobject_to_binary(value)
    else:
        try:
            return value.to_binary()
        except AttributeError:
            raise UaError("{} could not be packed with value {}".format(
                vtype, value))