Skip to main content

GetBusContext

Valid for: CANoe DE • CANoe4SW DE Note The bus context plays a role in modeling gateways and in tests of control units with several bus connections. In this case, a series of CAPL functions such as canOnline and canOffline may have more than one meaning in terms of the network interface (channel) to be used. A similar type of problem occurs when identical node layer modules are used simultaneously within a CAPL block. A distinction must be made between the instances of the node layer, both for calls to CAPL functions that are implemented in the node layers and for implementing callbacks. To facilitate this distinction, a bus context is placed in the CAPL program by the runtime environment while a callback is being executed by the node layer. This context unambiguously identifies the node layer that is making the call. In a similar manner, the call of a CAPL function that is implemented in a node layer is forwarded on to the appropriate node layer, depending on the current bus context. This also applies to the CAPL functions mentioned above, canOnline and canOffline, as well as to many wait points of the Test Feature Set. You should use the functions GetBusNameContext, GetBusContext and SetBusContext to determine the context of a bus, to query or to change the current bus context.

Function Syntax

dword GetBusContext();

Description

Returns the current bus context of the CAPL block.

Parameters

Return Values

The current bus context.

Example

This is an example for a simulation node.
Test nodes should copy the bus context to a CAPL variable in the Main() function because all global variables are cleared when the test module is started.
variables
{
    dword ibus_context = 0;
    dword motbus_context = 0;
}

on preStart
{
    ibus_context = GetBusNameContext( "ibus");
    motbus_context = GetBusNameContext( "motbus");
}

void apCanOn()
{
    dword context;

    // activate the CAN channel on the "current" context
    CanOnline();

    // determine the "other" context
    context = ibus_context == GetBusContext() ? motbus_context : ibus_context;
    // set the context to the "other" bus...
    SetBusContext( context);

    // ...and activate its CAN chip as well
    CanOnline();
}
GetBusNameContextSetBusContext