Exemplo n.º 1
0
def dtype_to_vtype(server, dtype_node):
    """
    Given a node datatype, find out the variant type to encode
    data. This is not exactly straightforward...
    """
    # first check if datatype is a simple built in type
    identifier = dtype_node.nodeid.Identifier
    if isinstance(identifier, int) and identifier <= 22:
        return ua.VariantType(identifier)
    # now handle some special cases
    parents = _get_node_supertypes(dtype_node)
    if not parents:
        raise ua.UaError("Datatype must be a subtype of builtin types")
    parent = parents[0]

    if parent.nodeid.Identifier == 29:
        # we have an enumeration, we need to llok at child to find type
        descs = dtype_node.get_children_descriptions()
        bnames = [d.BrowseName.Name for d in descs]
        if "EnumStrings" in bnames:
            return ua.VariantType.LocalizedText
        elif "EnumValues" in bnames:
            return ua.VariantType.ExtensionObject
        else:
            raise ua.UaError(
                "Enumeration must have a child node describing its type and values"
            )

    return dtype_to_vtype(server, parents[0])
Exemplo n.º 2
0
def data_type_to_variant_type(dtype_node):
    """
    Given a Node datatype, find out the variant type to encode
    data. This is not exactly straightforward...
    """
    base = get_base_data_type(dtype_node)

    if base.nodeid.Identifier != 29:
        return ua.VariantType(base.nodeid.Identifier)
    else:
        # we have an enumeration, value is a Int32
        return ua.VariantType.Int32
Exemplo n.º 3
0
def data_type_to_variant_type(dtype_node):
    """
    Given a Node datatype, find out the variant type to encode
    data. This is not exactly straightforward...
    """
    base = get_base_data_type(dtype_node)

    if base.nodeid.Identifier != 29:
        return ua.VariantType(base.nodeid.Identifier)
    else:
        # we have an enumeration, we need to look at child to find type
        descs = dtype_node.get_children_descriptions()
        bnames = [d.BrowseName.Name for d in descs]
        if "EnumStrings" in bnames:
            return ua.VariantType.LocalizedText
        elif "EnumValues" in bnames:
            return ua.VariantType.ExtensionObject
        else:
            raise ua.UaError(
                "Enumeration must have a child node describing its type and values"
            )
Exemplo n.º 4
0
def as_int(x):
    return ua.Variant(x, ua.VariantType(4))
Exemplo n.º 5
0
def as_time(x):
    return ua.Variant(x, ua.VariantType(8))
Exemplo n.º 6
0
dirs = [dir_right, dir_right, dir_down, dir_down, dir_down, dir_down, dir_down, dir_down,
        dir_right, dir_right, dir_up, dir_up, dir_up, dir_up, dir_up, dir_up,
        dir_right, dir_right, dir_down, dir_down, dir_down, dir_down, dir_down, dir_down,
        dir_right, dir_up, dir_up, dir_up, dir_up, dir_up, dir_up, dir_left,
        dir_down, dir_down, dir_down, dir_down, dir_down, dir_down, dir_left, dir_left,
        dir_up, dir_up, dir_up, dir_up, dir_up, dir_up, dir_left,  dir_left,
        dir_down, dir_down, dir_down, dir_down, dir_down, dir_down, dir_left, dir_left, dir_left]


for i, dir_ in enumerate(dirs):
    tr.get_node(f"{ROOT}.PLC_PRG.TAP_1.PIECE_T.dirs[{i}]").set_value(dir_)

"""
for i, tool in enumerate(tools):
    tr.get_node(f"{ROOT}.PLC_PRG.TAP_1.PIECE_T.tools[{i}]").set_value(tool)

for i, tool_time in enumerate(tool_times):
    tr.get_node(f"{ROOT}.PLC_PRG.TAP_1.PIECE_T.tool_times[{i}]").set_value(
        tool_time)

for i, tool_cnt in enumerate(tool_count):
    tr.get_node(f"{ROOT}.PLC_PRG.TAP_1.PIECE_T.tool_count[{i}]").set_value(
        tool_cnt)
"""

idx = as_int(0)
tr.get_node(f"{ROOT}.PLC_PRG.TAP_1.PIECE_T.idx").set_value(idx)

piece = ua.DataValue(ua.Variant(1, ua.VariantType(5)))
tr.get_node(f"{ROOT}.GVL.ST1_tp").set_value(piece)
Exemplo n.º 7
0
def as_seconds(x):
    return ua.Variant(x * 1000, ua.VariantType(8))
Exemplo n.º 8
0
def as_piece(x):
    return ua.Variant(x, ua.VariantType(5))