def main(): warnings.simplefilter(action="ignore", category=FutureWarning) logging.basicConfig() args = None parser = get_args() try: args = parser.parse_args() show_usage = args.help error_str = "" except (ArgumentParserError, argparse.ArgumentError, argparse.ArgumentTypeError) as e: print(e) show_usage = True error_str = "ERROR: " + str(e) # Make sure that SIGINT (i.e. Ctrl-C from command line) actually stops the # application event loop (otherwise Qt swallows KeyboardInterrupt exceptions) signal.signal(signal.SIGINT, signal.SIG_DFL) if show_usage: usage_str = parser.format_help() print(usage_str) usage = ShowUsage(usage_str, error_str) usage.configure_traits() sys.exit(1) # fail out if connection failed to initialize cnx_data = do_connection(args) if cnx_data is None: print('Unable to Initialize Connection. Exiting...') sys.exit(1) with cnx_data.driver as driver: with sbpc.Handler(sbpc.Framer(driver.read, driver.write, args.verbose)) as link: if args.reset: link(MsgReset(flags=0)) log_filter = DEFAULT_LOG_LEVEL_FILTER if args.initloglevel[0]: log_filter = args.initloglevel[0] with SwiftConsole(link, args.update, log_filter, cnx_desc=cnx_data.description, error=args.error, json_logging=args.log, log_dirname=args.log_dirname, override_filename=args.logfilename, log_console=args.log_console, connection_info=cnx_data.connection_info, expand_json=args.expand_json) as console: console.configure_traits() # TODO: solve this properly # Force exit, even if threads haven't joined try: os._exit(0) except: # noqa pass
baud, args.file, rtscts=rtscts) connection_description = os.path.split(port)[-1] + " @" + str(baud) else: # Use the port passed and assume serial connection print("Using serial device '%s'" % port) selected_driver = s.get_driver(args.ftdi, port, baud, args.file, rtscts=args.rtscts) connection_description = os.path.split(port)[-1] + " @" + str(baud) with selected_driver as driver: with sbpc.Handler(sbpc.Framer(driver.read, driver.write, args.verbose)) as link: if args.reset: link(MsgReset(flags=0)) log_filter = DEFAULT_LOG_LEVEL_FILTER if args.initloglevel[0]: log_filter = args.initloglevel[0] with SwiftConsole(link, args.update, log_filter, cnx_desc=connection_description, error=args.error, json_logging=args.log, log_dirname=args.log_dirname, override_filename=args.logfilename, log_console=args.log_console, networking=args.networking,
def main(): warnings.simplefilter(action="ignore", category=FutureWarning) logging.basicConfig() args = None parser = get_args() try: args = parser.parse_args() port = args.port baud = args.baud show_usage = args.help error_str = "" except (ArgumentParserError, argparse.ArgumentError, argparse.ArgumentTypeError) as e: print(e) show_usage = True error_str = "ERROR: " + str(e) if args and args.toolkit[0] is not None: ETSConfig.toolkit = args.toolkit[0] else: ETSConfig.toolkit = 'qt4' # Make sure that SIGINT (i.e. Ctrl-C from command line) actually stops the # application event loop (otherwise Qt swallows KeyboardInterrupt exceptions) signal.signal(signal.SIGINT, signal.SIG_DFL) if show_usage: usage_str = parser.format_help() print(usage_str) usage = ShowUsage(usage_str, error_str) usage.configure_traits() sys.exit(1) selected_driver = None connection_description = "" if port and args.tcp: # Use the TPC driver and interpret port arg as host:port try: host, ip_port = port.split(':') selected_driver = TCPDriver(host, int(ip_port)) connection_description = port except: raise Exception('Invalid host and/or port') sys.exit(1) elif port and args.file: # Use file and interpret port arg as the file print("Using file '%s'" % port) selected_driver = s.get_driver(args.ftdi, port, baud, args.file) connection_description = os.path.split(port)[-1] elif not port: # Use the gui to get our driver port_chooser = PortChooser(baudrate=int(args.baud)) is_ok = port_chooser.configure_traits() ip_address = port_chooser.ip_address ip_port = port_chooser.ip_port port = port_chooser.port baud = port_chooser.baudrate mode = port_chooser.mode # todo, update for sfw flow control if ever enabled rtscts = port_chooser.flow_control == flow_control_options_list[1] if rtscts: print("using flow control") # if the user pressed cancel or didn't select anything if not (port or (ip_address and ip_port)) or not is_ok: print("No Interface selected!") sys.exit(1) else: # Use either TCP/IP or serial selected from gui if mode == cnx_type_list[1]: print("Using TCP/IP at address %s and port %d" % (ip_address, ip_port)) selected_driver = TCPDriver(ip_address, int(ip_port)) connection_description = ip_address + ":" + str(ip_port) else: print("Using serial device '%s'" % port) selected_driver = s.get_driver(args.ftdi, port, baud, args.file, rtscts=rtscts) connection_description = os.path.split(port)[-1] + " @" + str( baud) else: # Use the port passed and assume serial connection print("Using serial device '%s'" % port) selected_driver = s.get_driver(args.ftdi, port, baud, args.file, rtscts=args.rtscts) connection_description = os.path.split(port)[-1] + " @" + str(baud) with selected_driver as driver: with sbpc.Handler(sbpc.Framer(driver.read, driver.write, args.verbose)) as link: if args.reset: link(MsgReset(flags=0)) log_filter = DEFAULT_LOG_LEVEL_FILTER if args.initloglevel[0]: log_filter = args.initloglevel[0] with SwiftConsole(link, args.update, log_filter, cnx_desc=connection_description, error=args.error, json_logging=args.log, log_dirname=args.log_dirname, override_filename=args.logfilename, log_console=args.log_console, networking=args.networking, serial_upgrade=args.serial_upgrade) as console: console.configure_traits() # Force exit, even if threads haven't joined try: os._exit(0) except: pass
# Make sure that SIGINT (i.e. Ctrl-C from command line) actually stops the # application event loop (otherwise Qt swallows KeyboardInterrupt exceptions) signal.signal(signal.SIGINT, signal.SIG_DFL) # Passing only a base station argument, we just want to display the # base station data in the console. Otherwise, continue, assuming a # rover connected to the serial port. if port is None and base is None: sys.stderr.write("ERROR: No data source specified!") sys.exit(1) if port is None and base and use_broker: device_id = get_uuid(channel, serial_id) with HTTPDriver(str(device_id), base) as http_driver: with sbpc.Handler(sbpc.Framer(http_driver.read, None, args.verbose)) as link: if os.path.isdir(log_filename): log_filename = os.path.join(log_filename, s.LOG_FILENAME) with s.get_logger(args.log, log_filename) as logger: link.add_callback(logger) log_filter = DEFAULT_LOG_LEVEL_FILTER if args.initloglevel[0]: log_filter = args.initloglevel[0] SwiftConsole(link, args.update, log_filter, True).configure_traits() try: os._exit(0) except: pass
self.port = self.ports[0] self.bauds = [ 4800, 9600, 19200, 38400, 43000, 56000, 57600, 115200 ] except TypeError: pass if not port: port_chooser = PortChooser() is_ok = port_chooser.configure_traits() port = port_chooser.port baud = port_chooser.baud if not port or not is_ok: print "No serial device selected!" sys.exit(1) else: print "Using serial device '%s', bauderate %d" % (port, baud) with s.get_driver(False, port, baud) as driver: with sbpc.Handler(sbpc.Framer(driver.read, driver.write, False)) as link: with s.get_logger() as logger: sbpc.Forwarder(link, logger).start() SwiftConsole(link).configure_traits() # Force exit, even if threads haven't joined try: os._exit(0) except: pass