Utilities

can.detect_available_configs(interfaces=None, timeout=5.0)[source]

Detect all configurations/channels that the interfaces could currently connect with.

This might be quite time-consuming.

Automated configuration detection may not be implemented by every interface on every platform. This method will not raise an error in that case, but will rather return an empty list for that interface.

Parameters:
  • interfaces (None | str | Iterable[str]) – either - the name of an interface to be searched in as a string, - an iterable of interface names to search in, or - None to search in all known interfaces.

  • timeout (float) – maximum number of seconds to wait for all interface detection tasks to complete. If exceeded, any pending tasks will be cancelled, a warning will be logged, and the method will return results gathered so far.

Return type:

list[dict]

Returns:

an iterable of dicts, each suitable for usage in the constructor of can.BusABC. Interfaces that timed out will be logged as warnings and excluded.

can.cli.add_bus_arguments(parser, *, filter_arg=False, prefix=None, group_title=None)[source]

Adds CAN bus configuration options to an argument parser.

Parameters:
  • parser (ArgumentParser) – The argument parser to which the options will be added.

  • filter_arg (bool) – Whether to include the filter argument.

  • prefix (str | None) – An optional prefix for the argument names, allowing configuration of multiple buses.

  • group_title (str | None) – The title of the argument group. If not provided, a default title will be generated based on the prefix. For example, “bus arguments (prefix)” if a prefix is specified, or “bus arguments” otherwise.

Return type:

None

can.cli.create_bus_from_namespace(namespace, *, prefix=None, **kwargs)[source]

Creates and returns a CAN bus instance based on the provided namespace and arguments.

Parameters:
  • namespace (Namespace) – The namespace containing parsed arguments.

  • prefix (str | None) – An optional prefix for the argument names, enabling support for multiple buses.

  • kwargs (Any) – Additional keyword arguments to configure the bus.

Returns:

A CAN bus instance.

Return type:

BusABC