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]
                         [--json-logfile JSON_LOGFILE] [--logfile LOGFILE]
                         [--merge-device-and-host-logs]
                         [--host-logfile HOST_LOGFILE]
                         [--device-logfile DEVICE_LOGFILE]
                         [--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

Enables debug logging when set.

--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”

--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[module] | None = None,
device_connection: DeviceConnection | None = None,
) int#

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
import pw_system.console

def main() -> int:
    return pw_system.console.main(
        compiled_protos=[
            common_pb2,
            echo_pb2,
        ]
        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[module] | 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'>) 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,
)


# 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}')