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 )
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)
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
if __name__ == '__main__': import os, sys, getopt try: opts, args = getopt.getopt( sys.argv[1:], '', longopts=['help', 'recycle', 'all', 'list', 'port=']) except getopt.GetoptError as err: 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