Exemplo n.º 1
0
def query( monitor_changes = True ):
    """
    Start a new LRS context, and collect all devices
    :param monitor_changes: If True, devices will update dynamically as they are removed/added
    """
    global rs
    if not rs:
        return
    #
    # Before we can start a context and query devices, we need to enable all the ports
    # on the acroname, if any:
    if acroname:
        acroname.connect()  # MAY THROW!
        acroname.enable_ports( sleep_on_change = 5 )  # make sure all connected!
    #
    # Get all devices, and store by serial-number
    global _device_by_sn, _context, _port_to_sn
    _context = rs.context()
    _device_by_sn = dict()
    try:
        log.d( 'discovering devices ...' )
        log.debug_indent()
        for dev in _context.query_devices():
            if dev.is_update_device():
                sn = dev.get_info( rs.camera_info.firmware_update_id )
            else:
                sn = dev.get_info( rs.camera_info.serial_number )
            _device_by_sn[sn] = Device( sn, dev )
            log.d( '...', dev )
    finally:
        log.debug_unindent()
    #
    if monitor_changes:
        _context.set_devices_changed_callback( _device_change_callback )
Exemplo n.º 2
0
def enable_only( serial_numbers ):
    """
    :param serial_numbers: A collection of serial-numbers to enable - all others' ports are
                           disabled and will no longer be usable!
    """
    ports = [ get_port( sn ) for sn in serial_numbers ]
    acroname.enable_ports( ports )
Exemplo n.º 3
0
def query(monitor_changes=True):
    """
    Start a new LRS context, and collect all devices
    :param monitor_changes: If True, devices will update dynamically as they are removed/added
    """
    global rs
    if not rs:
        return
    #
    # Before we can start a context and query devices, we need to enable all the ports
    # on the acroname, if any:
    if acroname:
        if not acroname.hub:
            acroname.connect()  # MAY THROW!
            acroname.enable_ports(
                sleep_on_change=5)  # make sure all connected!
    #
    # Get all devices, and store by serial-number
    global _device_by_sn, _context, _port_to_sn
    _context = rs.context()
    _device_by_sn = dict()
    try:
        log.d('discovering devices ...')
        log.debug_indent()
        for retry in range(3):
            try:
                devices = _context.query_devices()
                break
            except RuntimeError as e:
                log.d('FAILED to query devices:', e)
                if retry > 1:
                    log.e('FAILED to query devices', retry + 1, 'times!')
                    raise
                else:
                    time.sleep(1)
        for dev in devices:
            # The FW update ID is always available, it seems, and is the ASIC serial number
            # whereas the Serial Number is the OPTIC serial number and is only available in
            # non-recovery devices. So we use the former...
            sn = dev.get_info(rs.camera_info.firmware_update_id)
            device = Device(sn, dev)
            _device_by_sn[sn] = device
            log.d(
                '... port {}:'.format(device.port is None and '?'
                                      or device.port), sn, dev)
    finally:
        log.debug_unindent()
    #
    if monitor_changes:
        _context.set_devices_changed_callback(_device_change_callback)
Exemplo n.º 4
0
def query():
    """
    Start a new LRS context, and collect all devices
    """
    #
    # Before we can start a context and query devices, we need to enable all the ports
    # on the acroname, if any:
    acroname.connect()  # MAY THROW!
    acroname.enable_ports()
    #
    # Get all devices, and store by serial-number
    global _device_by_sn, _context, _port_to_sn
    _context = rs.context()
    _device_by_sn = {}
    for dev in _context.query_devices():
        if dev.is_update_device():
            sn = dev.get_info( rs.camera_info.firmware_update_id )
        else:
            sn = dev.get_info( rs.camera_info.serial_number )
        _device_by_sn[sn] = dev
Exemplo n.º 5
0
def enable_only( serial_numbers, recycle = False, timeout = 5 ):
    """
    Enable only the devices corresponding to the given serial-numbers. This can work either
    with or without Acroname: without, the devices will simply be HW-reset, but other devices
    will still be present.

    NOTE: will raise an exception if any SN is unknown!

    :param serial_numbers: A collection of serial-numbers to enable - all others' ports are
                           disabled and will no longer be usable!
    :param recycle: If False, the devices will not be reset if they were already enabled. If
                    True, the devices will be recycled by disabling the port, waiting, then
                    re-enabling
    :param timeout: The maximum seconds to wait to make sure the devices are indeed online
    """
    if acroname:
        #
        ports = [ get_port( sn ) for sn in serial_numbers ]
        #
        if recycle:
            #
            log.d( 'recycling ports via acroname:', ports )
            #
            acroname.disable_ports( acroname.ports() )
            _wait_until_removed( serial_numbers, timeout = timeout )
            #
            acroname.enable_ports( ports )
            #
        else:
            #
            acroname.enable_ports( ports, disable_other_ports = True )
        #
        _wait_for( serial_numbers, timeout = timeout )
        #
    elif recycle:
        #
        hw_reset( serial_numbers )
        #
    else:
        log.d( 'no acroname; ports left as-is' )
Exemplo n.º 6
0
def enable_all():
    """
    Enables all ports on an Acroname -- without an Acroname, this does nothing!
    """
    if acroname:
        acroname.enable_ports()
Exemplo n.º 7
0
def map_unknown_ports():
    """
    Fill in unknown ports in devices by enabling one port at a time, finding out which device
    is there.
    """
    if not acroname:
        return
    global _device_by_sn
    devices_with_unknown_ports = [
        device for device in _device_by_sn.values() if device.port is None
    ]
    if not devices_with_unknown_ports:
        return
    #
    ports = acroname.ports()
    known_ports = [
        device.port for device in _device_by_sn.values()
        if device.port is not None
    ]
    unknown_ports = [port for port in ports if port not in known_ports]
    try:
        log.d('mapping unknown ports', unknown_ports, '...')
        log.debug_indent()
        #log.d( "active ports:", ports )
        #log.d( "- known ports:", known_ports )
        #log.d( "= unknown ports:", unknown_ports )
        #
        for known_port in known_ports:
            if known_port not in ports:
                log.e("A device was found on port", known_port,
                      "but the port is not reported as used by Acroname!")
        #
        if len(unknown_ports) == 1:
            device = devices_with_unknown_ports[0]
            log.d('... port', unknown_ports[0], 'has', device.handle)
            device._port = unknown_ports[0]
            return
        #
        acroname.disable_ports(ports)
        wait_until_all_ports_disabled()
        #
        # Enable one port at a time to try and find what device is connected to it
        n_identified_ports = 0
        for port in unknown_ports:
            #
            log.d('enabling port', port)
            acroname.enable_ports([port], disable_other_ports=True)
            sn = None
            for retry in range(5):
                if len(enabled()) == 1:
                    sn = list(enabled())[0]
                    break
                time.sleep(1)
            if not sn:
                log.d('could not recognize device in port', port)
            else:
                device = _device_by_sn.get(sn)
                if device:
                    log.d('... port', port, 'has', device.handle)
                    device._port = port
                    n_identified_ports += 1
                    if len(devices_with_unknown_ports) == n_identified_ports:
                        #log.d( 'no more devices; stopping' )
                        break
                else:
                    log.w("Device with serial number", sn, "was found in port",
                          port, "but was not in context")
            acroname.disable_ports([port])
            wait_until_all_ports_disabled()
    finally:
        log.debug_unindent()
Exemplo n.º 8
0
     print('-F-', err)  # something like "option -a not recognized"
     usage()
 if args:
     usage()
 try:
     if acroname:
         if not acroname.hub:
             acroname.connect()
     action = 'list'
     for opt, arg in opts:
         if opt in ('--list'):
             action = 'list'
         elif opt in ('--all'):
             if not acroname:
                 log.f('No acroname available')
             acroname.enable_ports(sleep_on_change=5)
         elif opt in ('--port'):
             if not acroname:
                 log.f('No acroname available')
             all_ports = acroname.all_ports()
             str_ports = arg.split(',')
             ports = [
                 int(port) for port in str_ports
                 if port.isnumeric() and int(port) in all_ports
             ]
             if len(ports) != len(str_ports):
                 log.f('Invalid ports', str_ports)
             acroname.enable_ports(ports,
                                   disable_other_ports=True,
                                   sleep_on_change=5)
         elif opt in ('--recycle'):
Exemplo n.º 9
0
def enable_all():
    """
    """
    if acroname:
        acroname.enable_ports()