pw_system console CLI reference#
These are the standard pw_system console command line arguments.
usage: pw system console [-h] [-d DEVICE | -s SOCKET_ADDR] [-b BAUDRATE]
[--serial-debug]
[--token-databases elf_or_token_database [elf_or_token_database ...]]
[-f TICKS_PER_SECOND]
[--rpc-logging | --no-rpc-logging]
[--hdlc-encoding | --no-hdlc-encoding]
[--channel-id CHANNEL_ID]
[--device-tracing | --no-device-tracing] [-v]
[--host-log-level HOST_LOG_LEVEL]
[--device-log-level DEVICE_LOG_LEVEL]
[--json-logfile JSON_LOGFILE] [--logfile LOGFILE]
[--merge-device-and-host-logs]
[--host-logfile HOST_LOGFILE]
[--device-logfile DEVICE_LOGFILE]
[--debugger-listen | --no-debugger-listen]
[--debugger-wait-for-client | --no-debugger-wait-for-client]
[--config-file CONFIG_FILE] [--browser]
Named Arguments#
- -d, --device
the serial port to use
- -s, --socket-addr
Socket address used to connect to server. Type “default” to use localhost:33000, pass the server address and port as address:port, or prefix the path to a forwarded socket with “file:” as file:path_to_file.
- -b, --baudrate
the baud rate to use
Default: 115200
- --serial-debug
Enable debug log tracing of all data passed throughpyserial read and write.
- --token-databases
Path to tokenizer database csv file(s).
- -f, --ticks_per_second
The clock rate of the trace events.
- --rpc-logging, --no-rpc-logging
Use pw_rpc based logging. (default: True)
Default: True
- --hdlc-encoding, --no-hdlc-encoding
Use HDLC encoding on transfer interfaces. (default: True)
Default: True
- --channel-id
Channel ID used in RPC communications.
Default: 1
- --device-tracing, --no-device-tracing
Use device tracing. (default: True)
Default: True
- -v, --verbose
Set the host log level to debug.
- --host-log-level
Set the host log level (debug, info, warning, error, critical)
Default: 20
- --device-log-level
Set the device log level (debug, info, warning, error, critical)
Default: 10
- --json-logfile
Device only JSON formatted log file.
- --logfile
Default log file. This will contain host side log messages only unles the –merge-device-and-host-logs argument is used.
Default: “pw_console-logs.txt”
- --merge-device-and-host-logs
Include device logs in the default –logfile.These are normally shown in a separate device only log file.
- --host-logfile
Additional host only log file. Normally all logs in the default logfile are host only.
- --device-logfile
Device only log file.
Default: “pw_console-device-logs.txt”
- --debugger-listen, --no-debugger-listen
Start the debugpy listener. (default: False)
Default: False
- --debugger-wait-for-client, --no-debugger-wait-for-client
Pause console start until a debugger connects. (default: False)
Default: False
- --config-file
Path to a pw_console yaml config file.
- --browser
Start browser-based console instead of terminal.
Python Console APIs#
Functions for establishing a connection to pw_system powered devices using Python.
Console startup API#
- pw_system.console.main(
- args: Namespace | None = None,
- compiled_protos: list[ModuleType] | None = None,
- timestamp_decoder: Callable[[int], str] | None = None,
- device_connection: DeviceConnection | None = None,
- extra_frame_handlers: dict[int, Callable[[bytes, Any], Any]] | None = None,
Startup the pw console UI for a pw_system device.
Example usage:
from pw_protobuf_protos import common_pb2 from pw_rpc import echo_pb2 from pw_log.log_decoder.timestamp_parser_ms_since_boot import pw_system.console def main() -> int: return pw_system.console.main( compiled_protos=[ common_pb2, echo_pb2, ], timestamp_decoder=timestamp_parser_ms_since_boot, device_connection=None, ) if __name__ == '__main__': sys.exit(main())
Device connection API#
Device connections can be established in the same way as the pw_system console
but through the Python function create_device_serial_or_socket_connection()
.
- pw_system.device_connection.create_device_serial_or_socket_connection(device: str, baudrate: int, token_databases: ~typing.Collection[~pathlib.Path], socket_addr: str | None = None, ticks_per_second: int | None = None, serial_debug: bool = False, compiled_protos: list[~types.ModuleType] | None = None, rpc_logging: bool = True, channel_id: int = 1, hdlc_encoding: bool = True, device_tracing: bool = True, device_class: type[~pw_system.device.Device] | None = <class 'pw_system.device.Device'>, device_tracing_class: type[~pw_system.device_tracing.DeviceWithTracing] | None = <class 'pw_system.device_tracing.DeviceWithTracing'>, timestamp_decoder: ~typing.Callable[[int], str] | None = None, extra_frame_handlers: dict[int, ~typing.Callable[[bytes, ~typing.Any], ~typing.Any]] | None = None) DeviceConnection #
Setup a pw_system.Device client connection.
Full example of opening a device connection and running an RPC:
from pw_system.device_connection import ( add_device_args, create_device_serial_or_socket_connection, ) from pw_protobuf_protos import common_pb2 from pw_rpc import echo_pb2 parser = argparse.ArgumentParser( prog='MyProductScript', ) parser = add_device_args(parser) args = parser.parse_args() compiled_protos = [ common_pb2, echo_pb2, ] device_connection = create_device_serial_or_socket_connection( device=args.device, baudrate=args.baudrate, token_databases=args.token_databases, compiled_protos=compiled_protos, socket_addr=args.socket_addr, ticks_per_second=args.ticks_per_second, serial_debug=args.serial_debug, rpc_logging=args.rpc_logging, hdlc_encoding=args.hdlc_encoding, channel_id=args.channel_id, device_tracing=args.device_tracing, device_class=Device, device_tracing_class=DeviceWithTracing, timestamp_decoder=timestamp_parser_ms_since_boot, ) # Open the device connction and interact with the Device client. with device_connection as device: # Make a shortcut to the EchoService. echo_service = device.rpcs.pw.rpc.EchoService # Call some RPCs and check the results. result = echo_service.Echo(msg='Hello') if result.status.ok(): print('The status was', result.status) print('The message was', result.response.msg) else: print('Uh oh, this RPC returned', result.status) # The result object can be split into status and payload # when assigned. status, payload = echo_service.Echo(msg='Goodbye!') print(f'{status}: {payload}')