CAPL Script

GetBusNameContext

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Resolve a configured bus name

GetBusNameContext looks up the context belonging to a bus name in the CANoe configuration. Use it when your code knows which bus it needs but should not assume a hard-coded context value.

The name comes from Simulation Setup. A readable label in your project notes, a message name from a database and a physical channel label are not automatically interchangeable with that configured bus name.

Syntax and result

dword GetBusNameContext(char name[]);

The parameter is the configured bus name. A successful lookup returns its context. A return value of 0 means the specified bus does not exist. Resolving a name does not activate that context; use SetBusContext when a context-dependent operation needs a temporary switch.

Example: check the name before using the result

Replace BodyBus with the actual name from your configuration. This simulation-node example only logs the lookup result. It has not been compiled or executed in your environment.

variables
{
  char targetBus[32] = "BodyBus";
  dword targetContext;
}

on start
{
  targetContext = GetBusNameContext(targetBus);
  if (targetContext == 0)
  {
    write("Bus lookup failed: %s", targetBus);
    return;
  }
  write("Bus %s has context %u", targetBus, targetContext);
}

The failure branch deliberately stops before using the result. Passing an unresolved context into later operations would hide the original configuration error behind another symptom.

Verify both paths

  1. Start with an existing bus name and record whether the result is nonzero.
  2. Temporarily substitute a name that is absent from this test configuration. Confirm that the lookup-failure message appears and that subsequent context-dependent work is skipped.
  3. Restore the correct name and restart the measurement. If you rename a bus later, repeat the lookup rather than carrying a previously recorded numeric value into another configuration.

These are steps to run yourself, not recorded test results. For a test module, resolve the name during the module's own initialization; do not rely on simulation-node startup state being retained.

Troubleshooting

Symptom Check first
Lookup returns 0 Compare the string with the actual Simulation Setup name, including accidental whitespace
Lookup succeeds but the next operation uses the wrong bus Check whether the operation depends on the active context and whether you switched it
An unrelated operation changes after your helper runs Check that the previous context was restored after the temporary switch

Use GetBusContext to inspect the active context. It answers a different question from this name lookup.

Source and validation boundary

The signature and zero-result behavior follow the Vector GetBusNameContext reference, reproduced with permission. The diagnostic sequence above is explanatory guidance. See sources and permissions and the help shipped with your tool version.