Ejemplo n.º 1
0
def print_device_info(nodemap):
    """
    This function prints the device information of the camera from the transport
    layer; please see NodeMapInfo example for more in-depth comments on printing
    device information from the nodemap.

    :param nodemap: Transport layer device nodemap.
    :type nodemap: INodeMap
    :returns: True if successful, False otherwise.
    :rtype: bool
    """

    print('*** DEVICE INFORMATION ***\n')

    try:
        result = True
        node_device_information = PySpin.CCategoryPtr(nodemap.GetNode('DeviceInformation'))

        if PySpin.IsAvailable(node_device_information) and PySpin.IsReadable(node_device_information):
            features = node_device_information.GetFeatures()
            for feature in features:
                node_feature = PySpin.CValuePtr(feature)
                print('%s: %s' % (node_feature.GetName(),
                                  node_feature.ToString() if PySpin.IsReadable(node_feature) else 'Node not readable'))

        else:
            print('Device control information not available.')

    except PySpin.SpinnakerException as ex:
        print('Error: %s' % ex)
        return False

    return result
def print_category_node_and_all_features(node, level):
    """
    This function retrieves and prints out the display name of a category node
    before printing all child nodes. Child nodes that are also category nodes are
    printed recursively.

    :param node: Category node to get information from.
    :type node: INode
    :param level: Depth to indent output.
    :type level: int
    :return: True if successful, False otherwise.
    :rtype: bool
    """
    try:
        result = True

        # Create category node
        node_category = PySpin.CCategoryPtr(node)

        # Get and print display name
        display_name = node_category.GetDisplayName()
        print_with_indent(level, display_name)

        # Retrieve and iterate through all children
        #
        # *** NOTES ***
        # The two nodes that typically have children are category nodes and
        # enumeration nodes. Throughout the examples, the children of category nodes
        # are referred to as features while the children of enumeration nodes are
        # referred to as entries. Keep in mind that enumeration nodes can be cast as
        # category nodes, but category nodes cannot be cast as enumerations.
        for node_feature in node_category.GetFeatures():

            # Ensure node is available and readable
            if not PySpin.IsAvailable(node_feature) or not PySpin.IsReadable(
                    node_feature):
                continue

            # Category nodes must be dealt with separately in order to retrieve subnodes recursively.
            if node_feature.GetPrincipalInterfaceType(
            ) == PySpin.intfICategory:
                result &= print_category_node_and_all_features(
                    node_feature, level + 1)

            # Cast all non-category nodes as value nodes
            #
            # *** NOTES ***
            # If dealing with a variety of node types and their values, it may be
            # simpler to cast them as value nodes rather than as their individual types.
            # However, with this increased ease-of-use, functionality is sacrificed.
            elif CHOSEN_READ == ReadType.VALUE:
                result &= print_value_node(node_feature, level + 1)

            # Cast all non-category nodes as actual types
            elif CHOSEN_READ == ReadType.INDIVIDUAL:
                if node_feature.GetPrincipalInterfaceType(
                ) == PySpin.intfIString:
                    result &= print_string_node(node_feature, level + 1)
                elif node_feature.GetPrincipalInterfaceType(
                ) == PySpin.intfIInteger:
                    result &= print_integer_node(node_feature, level + 1)
                elif node_feature.GetPrincipalInterfaceType(
                ) == PySpin.intfIFloat:
                    result &= print_float_node(node_feature, level + 1)
                elif node_feature.GetPrincipalInterfaceType(
                ) == PySpin.intfIBoolean:
                    result &= print_boolean_node(node_feature, level + 1)
                elif node_feature.GetPrincipalInterfaceType(
                ) == PySpin.intfICommand:
                    result &= print_command_node(node_feature, level + 1)
                elif node_feature.GetPrincipalInterfaceType(
                ) == PySpin.intfIEnumeration:
                    result &= print_enumeration_node_and_current_entry(
                        node_feature, level + 1)

        print ""

    except PySpin.SpinnakerException as ex:
        print "Error: %s" % ex
        return False

    return result