def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description= "Utility for gathering information about connected Binho host Adapters" ) parser.add_argument( "-q", "--quiet", dest="quiet", action="store_true", help= "Prints only the device name and port of detected Binho host adapters", ) args = parser.parse_args() # Try to find all existing devices devices = binhoHostAdapter(find_all=True) if not devices: print("No Binho host adapters found!", file=sys.stderr) sys.exit(errno.ENODEV) # Print the board's information... for device in devices: if device.inBootloaderMode: if args.quiet: print(device.productName + " [DFU] (" + device.commPort + ")") device.close() continue # Otherwise, print the core information. print_core_info(device) elif device.inDAPLinkMode: if args.quiet: print(device.productName + " [DAPLink] (" + device.commPort + ")") device.close() continue print_core_info(device) else: # If we're in quiet mode, print only the serial number and abort. if args.quiet: print(device.productName + " (" + device.commPort + ")") device.close() continue # Otherwise, print the core information. print_core_info(device) print(" ") device.close()
import errno from serial import SerialException from binho.errors import DeviceNotFoundError # Included for demonstrating the various ways to find and connect to Binho host adapters # be sure to change them to match you device ID / comport targetComport = "COM3" targetDeviceID = "0x1c4780b050515950362e3120ff141c2a" # Start by finding the desired host adapter and connecting to it # wrap this with try/except to elegantly capture any connection errors try: # grab the first device found the system finds binho = binhoHostAdapter() # When working with multiple host adapters connected to the same system # you can use any of the following methods to connect: # 1) grab the device with a specific index # binho = binhoHostAdapter(index=0) # 2) or get the device using the COM port # binho = binhoHostAdapter(port=targetComport) # 3) or get the device using the deviceID number # binho = binhoHostAdapter(deviceID = targetDeviceID) except SerialException: