CANape#

class pycanape.canape.CANape(project_path: str | Path, fifo_size: int = 128, sample_size: int = 256, time_out: int = 0, clear_device_list: bool = True, modal_mode: bool = False, kill_open_instances: bool = True, **kwargs: Any)[source]#

Initialize and start the CANape runtime environment.

The first parameter sets the project path where the A2L file and the other configuration files are located. The FIFO and sample size buffer are used for the measurement buffer. The whole memory is calculated by the following formula: Size = FIFO * sample.

Parameters:
  • project_path (str | Path) – Sets the path of the working folder

  • fifo_size (int) – Sets the FIFO buffer size for the measurement

  • sample_size (int) – Sets the sample buffer size for the measurement

  • time_out (int) – Sets the timeout in ms

  • clear_device_list (bool) – clear_device_list = True -> all devices are cleared clear_device_list = False -> all devices are added, which are described in the CANape.ini

  • modal_mode (bool) – Sets the start mode of CANape Value: modal_mode = True -> non-modal (Python Client and CANape) modal_mode = False -> modal (only Python Client)

  • kill_open_instances (bool) – If True, close all open CANape instances before start.

  • kwargs (Any) –

create_module(module_name: str, database_filename: str | Path, driver: DriverType, channel: Channels, go_online: bool = True, enable_cache: int = -1) Module[source]#

The create_module function is used for creating a new module/device and for loading an ASAP2 file or a DB file. The function configures the logical communication channel which will be used (like CCP: 1-4 = CAN1-CAN4) and the driver type like KWPOnCAN, or CCP. The return value contains the instance of the Module class.

Example:

module = canape.create_module(
    module_name="CCPSim",
    database_filename="C:\Program Files\CANape\CCPsim\CCPSIM.a2l",
    driver=defines.tDriverType.ASAP3_DRIVER_CCP,
    channel=defines.Channels.DEV_CAN1,
)

Note

If the XCP driver is used, the channel for TCP/IP or UDP has to be set to the value TCP = 255 or UDP = 256 and for FlexRay = 261.

Parameters:
  • module_name (str) – Name of the module to create

  • database_filename (str | Path) – Sets the path and the name of the a2l or db file

  • driver (DriverType) – Set driver type

  • channel (Channels) – Set the logical communication channel to be used from CANape

  • go_online (bool) – indicates, that the new device need to switched ONLINE (allows to create OFFLINE devices)

  • enable_cache (int) – enabled the cache (1) oder disables it (0) if this parameter should be ignored it has to be set to (-1)

Returns:

The instance of the Module class

Return type:

Module

define_recorder(recorder_name: str, recorder_type: RecorderType = RecorderType.eTRecorderTypeMDF) Recorder[source]#

Creates a new Recorder.

Parameters:
  • recorder_name (str) – the name of the new Recorder

  • recorder_type (RecorderType) – recorder type (e.g. eTRecorderTypeMDF, eTRecorderTypeILinkRT or eTRecorderTypeBLF)

Returns:

an instance of the Recorder class

Return type:

Recorder

exit(close_canape: bool = True) None[source]#

Shut down ASAP3 connection to CANape with optional termination of CANape.

Parameters:

close_canape (bool) – close CANape application if True

Return type:

None

get_application_version() AppVersion[source]#

Call this function to get the current version of the server application.

Return type:

AppVersion

get_cna_filename() str[source]#

Call this function to get the current name of the used CNA file. This name is only available if CANape run in the nonmodal ASAP3 mode.

Returns:

Path to .cna file

Return type:

str

get_dll_version() DllVersion[source]#

Version control

Return type:

DllVersion

get_measurement_state() MeasurementState[source]#

Get the current state of the measurement.

Return type:

MeasurementState

get_module_by_index(module_index: int) Module[source]#

Get existing module (created by another application) by index.

Parameters:

module_index (int) – index of device

Returns:

an instance of the Module class

Return type:

Module

get_module_by_name(module_name: str) Module[source]#

Get existing module (created by another application) by name.

Parameters:

module_name (str) – name of device

Returns:

an instance of the Module class

Return type:

Module

get_module_count() int[source]#

Returns the count of instantiated Modules in the current Project.

Returns:

number of modules

Return type:

int

get_project_directory() str[source]#

Get the current project Directory.

Return type:

str

get_recorder_by_index(index: int) Recorder[source]#
Parameters:

index (int) –

Return type:

Recorder

get_recorder_count() int[source]#

Return count of defined Recorders.

Return type:

int

get_selected_recorder() Recorder[source]#

Retrieve the currently selected Recorder

Return type:

Recorder

has_mcd3_license() bool[source]#

Check if the MCD option is enabled.

Return type:

bool

is_network_activated(network_name: str) bool[source]#

Receives the state a given network interface.

Parameters:

network_name (str) – The name of the network as string

Returns:

state of network (True = active) or (False = disactivated)

Return type:

bool

load_cna_file(cna_file: str | Path) None[source]#

Call this function to load a configuration file (CNA).

Parameters:

cna_file (str | Path) –

Return type:

None

popup_debug_window() None[source]#

Trouble shooting: call this function to popup the debug window of the MCD-system.

Return type:

None

register_callback(event_code: EventCode, callback_func: Callable[[], Any]) None[source]#
Parameters:
Return type:

None

reset_data_acquisition_channels() None[source]#

Clears the data acquisition channel list.

Note

this function only clears these measurement objects from the API-Measurement-List which are defined by API

Return type:

None

set_interactive_mode(mode: bool) None[source]#

Enables the Interactive mode of CANape.

Parameters:

mode (bool) – Set this parameter to true to enable the interactive mode, otherwise set this paramater to false

Return type:

None

start_data_acquisition() None[source]#

Start data acquisition.

Return type:

None

stop_data_acquisition() None[source]#

Stop data acquisition.

Return type:

None

unregister_callback(event_code: EventCode, callback_func: Callable[[], Any]) None[source]#
Parameters:
Return type:

None

class pycanape.canape.AppVersion(main_version, sub_version, service_pack, app_name)[source]#

Create new instance of AppVersion(main_version, sub_version, service_pack, app_name)

Parameters:
  • main_version (int) –

  • sub_version (int) –

  • service_pack (int) –

  • app_name (str) –

app_name: str#

Alias for field number 3

main_version: int#

Alias for field number 0

service_pack: int#

Alias for field number 2

sub_version: int#

Alias for field number 1

class pycanape.canape.DllVersion(dll_main_version, dll_sub_version, dll_release, os_version, os_release)[source]#

Create new instance of DllVersion(dll_main_version, dll_sub_version, dll_release, os_version, os_release)

Parameters:
  • dll_main_version (int) –

  • dll_sub_version (int) –

  • dll_release (int) –

  • os_version (str) –

  • os_release (int) –

dll_main_version: int#

Alias for field number 0

dll_release: int#

Alias for field number 2

dll_sub_version: int#

Alias for field number 1

os_release: int#

Alias for field number 4

os_version: str#

Alias for field number 3