BFGTL.py#

#############################################################
 # 
 # FILE:        BFGTL.py
 # DATE:        1/6/2022
 # COMPANY:     BitFlow, Inc.
 # DESCRIPTION: Example program demonstrating the use of the BFGTLUtils
 #              sub-module to access and control GenICam devices.
 #
#############################################################

import platform
import sys

if(platform.system() == 'Windows'):
    import msvcrt
    
    if (sys.version_info.major >= 3 and sys.version_info.minor >= 8):
        import os
        #Following lines specifying, the location of DLLs, are required for Python Versions 3.8 and greater
        os.add_dll_directory("C:\BitFlow SDK 6.5\Bin64")
        os.add_dll_directory("C:\Program Files\CameraLink\Serial")

from BFModule import BFGTLUtils as BFGTL


# Function to modify the node value, call only if the node is writable
def modifyNodeValue(node, nodeType):
    if(nodeType == BFGTL.BFGTLNodeType.Integer):
        try:
            val = int(input('Enter new value: '))
        except:
            print('Write failed. Value has to be an Integer Value.')
        else:
            node.IntValue = val
            return
    elif(nodeType == BFGTL.BFGTLNodeType.Boolean):
        val = input('Enter new value (T/F): ')
        value = False
        if(val.upper() == 'T'):
            value = True
        elif(val.upper() == 'F'):
            value == False
        else:
            print('Write failed. Value has to be a Boolean Value.')
            return
        node.BooleanValue = value
        return
    elif(nodeType == BFGTL.BFGTLNodeType.Float):
        try:
            val = float(input('Enter new value: '))
        except Exception as e:
            print(e)
            print('Write failed. Value has to be a Float Value.')
        else:
            node.FloatValue = val
            return
    elif(nodeType == BFGTL.BFGTLNodeType.String):
        try:
            val = input('Enter new value: ')
        except:
            print('Write failed. Value has to be a String.')
        else:
            node.StrValue = val
            return
    elif(nodeType == BFGTL.BFGTLNodeType.Command):
        node = BFGTL.CommandNode(baseNode)
        print('Hit \'1\' to send command')
        keyPressed = msvcrt.getch().decode('utf-8')
        if(keyPressed == "1"):
            node.Execute
    elif(nodeType == BFGTL.BFGTLNodeType.Enumeration):
        try:
            val = int(input("Select an index from the list above - "))
        except:
            print("Invalid Selection.")
        else:
            if(val < 0 or val > node.EntryCount):
                print("Invalid Selection.")
            else:
                node.EntrySymbolic = node.EntrySymbolics[val]
                print(node.EntrySymbolics[val])

#Function to read and print the node details, along with the node value (if node is readable)
def printNodeDetails(Node):
    print("\nNode Name:\t ", Node.DisplayName)
    print("Tool tip:\t ", Node.ToolTip)
    print("Description:\t ", Node.Description)

    nodeType = Node.NodeType
    nodeAccess = Node.NodeAccess
    print("Type:\t\t ", nodeType)
    print("Access:\t\t ", nodeAccess)

    if(nodeAccess == BFGTL.BFGTLAccess.RO or nodeAccess == BFGTL.BFGTLAccess.RW):
        if(nodeType == BFGTL.BFGTLNodeType.Integer):
            node = BFGTL.IntegerNode(Node)
            print("\nValue = ", node.IntValue, '(', hex(node.IntValue), ')')
            print("Max = ", node.Maximum, '(', hex(node.Maximum), ')'," Min = ", node.Minimum, '(', hex(node.Minimum), ')')
        elif (nodeType == BFGTL.BFGTLNodeType.Boolean):
            node = BFGTL.BooleanNode(Node)
            print("\nValue = ", node.BooleanValue)
        elif (nodeType == BFGTL.BFGTLNodeType.Float):
            node = BFGTL.FloatNode(Node)
            print("\nValue = ", node.FloatValue)
            print("Max = ", node.Maximum," Min = ", node.Minimum)
        elif (nodeType == BFGTL.BFGTLNodeType.String):
            node = BFGTL.StringNode(Node)
            print("\nValue = ", node.StrValue)
            print("Max Length = ", node.MaxLength)
        elif (nodeType == BFGTL.BFGTLNodeType.Category):
            node = BFGTL.CategoryNode(Node)
            print("\nFeature Count = ", node.getFeatureCount)
            print("Feature Names = ", *node.getFeatureNames, sep = "\n\t-")
        elif (nodeType == BFGTL.BFGTLNodeType.Enumeration):
            node = BFGTL.EnumerationNode(Node)
            print("\nValue = ", node.EntrySymbolic)
            for i in range(0, node.EntryCount):
                print(i,'. ', node.EntrySymbolics[i])
        elif (nodeType == BFGTL.BFGTLNodeType.EnumEntry):
            node = BFGTL.EnumEntryNode(Node)
            print("\nValue = ", node.getValue)
            print("Symbolic = ", node.getSymbolic)
                        
        if(nodeAccess == BFGTL.BFGTLAccess.WO or nodeAccess == BFGTL.BFGTLAccess.RW):
            modifyNodeValue(node, nodeType)
            

# The main function
def main():
    
    #lib = BFGTL.Library()
    #if(not(lib.isGood)):
    #    sys.exit("BFGTL Library not installed")

    dev = BFGTL.BFGTLDevice()
    try:
        dev.Open()
    except Exception as e:
        print(e)
        sys.exit(0)
    else:
        NodeNames = dev.getNodeNames()
        featureNodes = []

        baseNode = dev.getNode(NodeNames[0])
        printNodeDetails(baseNode)

        keepLooping = True
        while keepLooping:
            nodeName = input("\nEnter name of the node (or enter \'exit\' to exit): ")

            if(nodeName.upper() == 'EXIT'):
                keepLooping = False
                break
            else:
                nodeFound = False
                for i in NodeNames[1:]:
                    baseNode = dev.getNode(i)
                    if (baseNode.Name.upper() == nodeName.upper()):
                        nodeFound = True
                        printNodeDetails(baseNode)
                        break

                if(not(nodeFound)):
                    print('Node not found. Try again.')
                    continue

        dev.Close()

if __name__ == "__main__":
    main()