AN-IND-1-011 Using CANoe NET API
AN-IND-1-011 Using CANoe NET API
NET API
Version 2.8
2018-02-12
Application Note AN-IND-1-011
Table of Contents
1.0 Document History .........................................................................................................................2
2.0 Glossary .........................................................................................................................................2
3.0 Introduction ...................................................................................................................................3
3.1.1 Prepare Visual Studio to be used as .NET Editor ................................................................3
3.1.2 Add a .NET Test Module ......................................................................................................3
3.1.3 Create a CANoe configuration specific .NET Test Library...................................................4
3.1.4 Create a .NET Test Library that is independent from a CANoe configuration .....................5
3.1.5 Next Steps ............................................................................................................................5
4.0 Environment ..................................................................................................................................6
4.1 CANoe .NET API Components ............................................................................................6
4.2 .NET Editor...........................................................................................................................7
4.3 .NET Programs in CANoe ....................................................................................................7
4.3.1 .NET Test Modules ..............................................................................................................8
4.3.2 .NET Simulation Nodes ........................................................................................................8
4.3.3 .NET Snippets ......................................................................................................................8
4.3.4 .NET Test Libraries ..............................................................................................................8
4.3.5 .NET Test Module and CAPL Test Cases / Test Functions ..............................................10
4.3.6 .NET Test units ..................................................................................................................10
4.4 Additional Information and CANoe Examples ....................................................................11
5.0 Programming with the CANoe .NET API ...................................................................................11
5.1 Common Features .............................................................................................................11
5.1.1 Signals (bus signals, environment and system variables) .................................................11
5.1.2 Messages ...........................................................................................................................12
5.1.3 Timer ..................................................................................................................................12
5.1.4 Event Procedures...............................................................................................................13
5.2 Test Features .....................................................................................................................14
5.2.1 Test Module Types ............................................................................................................14
5.2.2 Reporting Commands ........................................................................................................16
5.2.3 Wait Points .........................................................................................................................16
5.2.4 Checks ...............................................................................................................................17
5.2.5 Criterions ............................................................................................................................18
5.2.6 User Dialogs .......................................................................................................................19
5.2.7 Test Patterns ......................................................................................................................19
5.2.8 Diagnostic Tests.................................................................................................................20
6.0 Migrating a .NET Module that was created with CANoe < 7.6SP3..........................................21
6.1 Migrating from .NET2 API to .NET4 API ............................................................................21
6.1.1 Migrating the CANoe configuration ....................................................................................21
6.1.2 Migrating .NET Test Modules and Test Libraries ..............................................................21
7.0 Background Information (for Experts) ......................................................................................22
7.1 Real-time Performance ......................................................................................................22
Using CANoe .NET API
Version 2.7
> New document template and minor changes.
Version 2.6
> .NET4 support, test units, post compiler.
Version 2.5
> Glossary updated, minor changes.
Version 2.4
> Note about .NET framework version added (chapter 3.0)
Version 2.3
> Project templates for .NET test libraries that are independent from CANoe’s configurations
Version 2.2
> Document structure revised
> Glossary added
> Quick start instructions (chapter 0)
> .NET test libraries for XML and .NET test modules (chapter 4.3.4)
> Overview of reporting elements (chapter 5.2.2)
> Diagnostic tests (chapter 5.2.8)
2.0 Glossary
CANoe .NET API
A set of .NET assemblies (.dlls) providing access to CANoe’s functionality.
CAPL Library
A collection of CAPL test cases and test functions that can be used from your .NET program.
Snippet
A small piece of .NET program code that can be executed like a macro. Snippets can be changed and
recompiled while measurement is running.
3.0 Introduction
The CANoe environment provides a .NET API to be used for simulation, test, and snippet
programming. The CANoe .NET API is an Embedded Domain Specific Language extension that offers
the possibility to use object-oriented programming languages, e.g. C# in the CANoe environment.
.NET languages provide extended capabilities to structure, to reuse and to debug programs.
This document uses C# as recommended programming language. Nevertheless also other .NET
languages like Visual Basic .NET can be used.
CANoe currently supports the .NET4 framework.
A .NET 2 version of the CANoe API is still provided for binary compatibility to your existing DLLs. If
you have the sources it is recommended to switch to the .NET 4 API version, since the .NET 2 API is
fixed to the functional range of CANoe 8.2 SP2. Further development will only support the .NET 4 API.
The .NET API can be used as an alternative to CAPL for test module or simulated node programming.
It can also be used for programming so-called snippets, mainly used for simple stimulation or
initialization purposes.
Discussed in this document is the .NET API concept and its usage in CANoe. It is assumed that the
reader is familiar with the .NET framework and the application note AN-IND-1-002 Testing with
CANoe.
This document does not primarily addresses test unit developers. However the chapters 5.0 and 7.0
are also relevant for test unit development.Quick Start
6. Open the configuration dialog for the new test module. Enter a new test module name and a new
source file name with a ‘.cs’ extension.
7. Click on ‘Edit’.
The test module skeleton and a solution is created and opened in Visual Studio. User added code is
shown in bold and demonstrates some basic CANoe .NET API features.
using System;
using Vector.Tools;
using Vector.CANoe.Runtime;
using Vector.CANoe.Threading;
using Vector.Diagnostics;
using Vector.Scripting;
using Vector.Scripting.UI;
using Vector.CANoe.TFS;
using NetworkDB;
using Vector.CANoe.VTS;
using NetworkDB;
[TestFunction("SetValue")]
public void SetValue(int a)
{
NetworkDB.database1.SigStart.Value = a;
}
}
3.1.4 Create a .NET Test Library that is independent from a CANoe configuration
This chapter describes how to create a test library that is independent from the CANoe’s configuration,
i.e. it does not need references to configuration dependent type libraries. As an advantage such a
library can be used in any CANoe configuration but some special handling is necessary when
accessing configuration specific data, e.g. signals.
Visual Studio will offer a .NET test library template project when you copy
C:\...\CANwin Demos\Demo_Addon\VS_DotNetTestLibary_Template\CANoe DotNet Test Library.zip
to your Visual Studio CSharp Project Template folder, typically located here:
C:\Users\<username>\Documents\Visual Studio <vs_version>\Templates\ProjectTemplates\Visual C#
You can check the template folder in your Visual Studio Options dialog (menu: Projects and Solutions |
General | User project templates location).
At next a new .NET test library can be created in Visual Studio with menu: File | New | Project | Visual
C# and selecting 'CANoe DotNet Test Library'. Before confirming the dialog with ‘OK’ you should
select a library name and the folder.
After a first compilation the assembly can be added to the XML tester components.
4.0 Environment
When editing a .NET program (IDE started with CANoe) and no solution is found in the configuration
folder CANoe creates a solution with all needed API references.
Note CANoe supports generation but not modification of the VS solution/project file. If more
components are added in the node configuration dialog or if a new database is added, these
libraries must be added manually as references to the VS project.
> Vector.CANoe.Sockets
Contains network access functionality.
> <DB name>.dll
For all messages and signals and environment variables in the CAN database this assembly
contains class definitions. The assembly is automatically generated and updated by CANoe.
> <configuration name>.cfg_sysvars.dll
This assembly contains class definitions for all system variables used in the configuration file. The
assembly is automatically generated by CANoe.
> <system variable file>.dll
For each external system variable file CANoe creates a library file to access the system variables.
> <program name>_CaplLibraries.dll
Contains the functions to access CAPL test cases and test functions from within .NET test
modules
For a complete API description please check the CANoe online help.
Note1: All .NET programs are executed in the runtime environment of CANoe and can slow down or
even block the simulation.
Note2: This document describes the .NET API available with CANoe version 8.2.
Note3: For older versions some restrictions apply, please refer to the online help for detailed
information
The .NET2 API additionally uses PostSharp.Public and PostSharp.Laos for post compilation purposes.
They are not used in the .NET4 API anymore.
Note: It is important to configure the vbs script, and not the exe file of the editor, in CANoe.
A solution file should be used if the .NET program is subdivided in several source files or modules. It is
recommended to let CANoe create the solution automatically. This is done by configuring a non-
existing solution file name in the test module/node configuration dialog in CANoe and pressing the
[Edit] button. The generated solution is opened with the chosen IDE, including all correct settings.
You can implement a test library that is independent from the CANoe configuration (see 3.1.4) or a
library that contains references to the type libraries specific for a CANoe configuration, see 3.1.3.
A .NET test library consists of a public class which doesn’t need to derive from any Vector API class
and which does not need to implement the main() method. All public member functions with dedicated
parameters and without return value that are marked with the TestCase or TestFunction are available
in the test module. Event procedures in the .NET Test Library are only called during runtime of the
.NET test case.
The resulting test library assembly can be added to an XML or .NET test module via the component
tab of the node configuration dialog. The test library assembly must be located in the same folder as
the test module.
When a test library itself references further assemblies these assemblies should be declared in the
node configuration dialog. This way CANoe will be able to transfer all components when the simulation
process is executed on a remote computer.
Note All .NET Test Libraries under the Component tab in Test Module Configuration dialog will be
added as references to the VS project of the test module, as long as they were configured
before the creation of the test module project file.
It is important to differ between a .NET test module (Main() method is also implemented in .NET) and
an XML test module with a .NET test case library.
In a.NET test module all variables are valid during the whole test. But if test cases from a library are
used in an XML test module the test cases are independent from each other, i.e. each test case is
instantiated once and variables are valid during test execution.
It should be noted that test cases implemented in a library may be called in an arbitrary sequence and
should be treated according to this principle (initialization, usage, cleanup).
XML test module using .NET Test Libraries
.NET test functions are called with a <nettestfunction> XML element inside XML test cases. It is
possible to call several different test functions within the same test case.
<testcase title="My Test case Title" ident="">
<nettestfunction name="MyTestFunction" title="Calling a NET test function"
class="LockStateDependsOnlyOnVelocity" assembly="TestLibrary">
<netparam type="int" name="myInt">10</netparam>
</nettestfunction>
</testcase>
Parameter types can be numerical values, strings, signals, environment and system variables.
XML type .NET type
int UInt64, UInt32, UInt16, Int64, Int32, Int16
float Double
string String
signal Vector.CANoe.Runtime.Signal
envvar Vector.CANoe.Runtime.EnvironmentVariable
sysvar Vector.CANoe.Runtime.SystemVariableBase
In contrast to the value types (int, float, string), the signal types are declared as Generics in the test
case. Constraints must be applied to these Generics in order to guarantee type reliability. The specific
types Signal, EnvironmentVariable or SystemVariableBase can be used for this.
The following definition is required if you want to use a test case for all three signal types similarly:
[TestCase]
public void SetSignal<T>(Double d) where T : class, IRuntimeValue
{
RuntimeObject<T>.Value = d;
}
4.3.5 .NET Test Module and CAPL Test Cases / Test Functions
CAPL files can be assigned to a .NET test module with the test module configuration dialog. All CAPL
test functions and test cases can be called from the .NET test module.
Not all CANoe features are available in the .NET API (this especially concerns bus system specifics)
but with CAPL test libraries you can easily access the complete functionality.
CAPL libraries that are assigned to the .NET test module are structured like CAPL test modules, but
they must not contain a MainTest() routine. Event procedures are only called during runtime of the
.NET test module. All event procedures of the assigned CAPL libraries are considered except ‘on start’
and ‘on stop’.
CAPL test cases and test functions may use parameter types ‘char, char[], byte, int, long, float,
double’. Results can be returned via system or environment variables.
A CAPL test case or test function can be called like any other .NET method. If they are used in
structured test module they have to be wrapped by a .NET test case or a TestGroup method.
CaplTestCases.CaplTestLib.MyTestCase(“test”);
CaplTestFunctions.CaplTestLib.MyTestFunction(23.0);
Both have been defined in a CAPL library “CaplTestLib.can” and a reference for this library is
configured in the .NET solution. The CAPL library looks like this:
testcase MyTestCase (char s[])
{
…
}
testfunction MyTestFunction (double d)
{
…
}
In the signal-based view CAN, LIN and FlexRay bus signals are supported.
Note that setting the value usually doesn't change the value directly; in case of signals, the current
value is only changed after a message which contains the signal has been transmitted on the bus and
received again.
Environment variables can be handled in the same way, e.g.
MyIntegerEv.Value = 1;
In case the environment variable is a data array type you can easily read each byte with the index
operator:
if (MyDataEv.Value[2] == 2) {…}
It is also possible to dynamically create a signal object when its name is known. Here is an example
how to create a system variable object (namespace = ‘Tester’ and variable name = ‘Enabled’) and to
modify its value:
DynamicSystemVariable var = new DynamicSystemVariable("Tester", "Enabled");
var.Value = 1;
5.1.2 Messages
In the message-based view CAN messages are supported in a first step. For the CAN frames that are
defined in databases, specific classes are generated in type libraries.
To construct a user-defined CAN message which is not defined in a database (e.g. dbc), the class
CANFrame can be used as a super class. Signals are defined with the [Signal] attribute. Their offset
and the least significant bit of the signal are as a bit number. Signal overlap etc will be checked at
compile time.
CAN messages can also be declared by creating instances of the CANFrame class and initializing the
ID and DLC in the constructor. Message data can only be set in raw format, either byte-wise using the
property Bytes[] or by a byte array which must be of size 8 bytes min:
byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
CANFrame msg = new CANFrame(0x500, 4); // ID=0x500, DLC=4
msg.SetRawData(data);
msg.Send();
To implement different send models CANoe is able to use so-called interaction layers realized by
DLLs. OEMs often use specific interaction layers but there is also a generic Vector Interaction Layer
available. If an interaction layer is used in the CANoe configuration, it is sufficient to set signal values
without having to send messages explicitly – messages will be sent according to the correct send
model by CANoe (e.g. cyclic messages will be sent automatically according to the required cycle time
and sending mode).
Note that message objects in the configured databases are always created in a subordinate
namespace called Frames to prevent possible conflicts with signal classes. Access to e.g. message
VehicleMotion is accomplished through NetworkDB.Frames.VehicleMotion.
5.1.3 Timer
The attribute [OnTimer] can be used to accomplish a cyclic timer. The method will be executed
cyclically at the defined time point (here 1s).
For test modules the timer is active when the test module is active and for simulation nodes it is active
during measurement.
[OnTimer(1000))]
public void OnTimer1s() {
Output.Writeline("Timer elapsed");
}
If a timer should be started and stopped at a certain point, timer objects can be used instead. Use the
Timer class and its properties/methods, e.g. define a timer handler:
{
Timer t = new Timer(new TimeSpan(0, 0, 0, 0, 250),TimerHandler);
t.Start();
…
t.Stop();
}
For test modules the event handlers are active when the test module is active and for simulation
nodes they are active during measurement.
A handler that reacts on value changes of the network signal LockState is defined like this:
[OnChange(typeof(LockState))]
public void OnSignalLockState() {
double value = LockState.Value;
}
The .NET signal-oriented API only supports ‘on change’ handlers in contrast to CAPL that supports
both ‘on change’ and ‘on update’ handlers. One reason is the performance aspect in .NET programs.
Another reason is that the signal based tests are state-based.
In contrast to this message handlers (introduced with version 7.1) are event-based. To handle a
message event for message WindowState use the [OnCANFrame] attribute. The CAN channel and
message ID can also be specified in the attribute constructor.
[OnCANFrame]
public void onMessage(NetworkDB.Frames.WindowState frame) {
double pos = frame.WindowPosition.Value;
}
[OnCANFrame(1, 500)]
public void Frame500Received(CANFrame frame) {…}
Use the attribute [OnKey] to react on key events. The defined method must have one char parameter.
[OnKey('+'))]
public void OnKeyPressed(char ch) {
Output.WriteLine("+ was pressed");
}
To handle timer events the [OnTimer] attribute should be used. The method TimerElapsed below will
be called every 500 ms:
[OnTimer(500))]
public void TimerElapsed() {
msg.Send();
}
Both module types are very similar and their format is described in the following chapters.
Unstructured test modules
An unstructured.NET test module must inherit from class Vector.CANoe.TFS.TestModule. It consists
primarily of the Main method where the test control flow and the test cases are executed. Test groups
can be used to organize test cases that belong together. Test cases are defined with the custom
attribute [TestCase] and can be divided into test steps. The Vector.CANoe.TFS.Report class is
used for reporting to the report file.
The Main method of the test module is the main program of the test module analog to a CAPL test
module. It is required to override the inherited Main method of the TestModule class. The main
method groups test cases and executes them sequentially:
The Main method should only contain test flow control. The concrete tests should be done in the test
cases. Complex flow logic can be implemented, e.g. letting a test case execute multiple times by
calling it in a loop or prevent execution of a test case if a preceding test case returned failure.
In general test cases should be programmed such that they don’t depend on each other, e.g. by not
using global variables between test cases. It is recommended to start every test case from anew;
initialize parameters before test case start and – if needed – reset parameters after test case end. This
ensures good programming practice and possible code re-use (which is one of the main motivations
for the .NET API).
Event procedures are only active during test module run-time since test modules need not always be
active during the whole measurement time (see also AN-IND-1-002 Testing with CANoe).
Structured test modules
A structured.NET test module must inherit from class Vector.CANoe.TFS.StructuredTestModule.
The StructuredMain method of the test module is the main program and it is required to override the
inherited StructuredMain method of the StructuredTestModule class.
It is required that dynamic test sequences (test sequences that may vary between two test runs) are
encapsulated with methods that are marked with the [TestGroup] attribute. A dynamic test group will
always be executed as a whole.
The example shows a DynamicTestGroup() and a normal test group with two test cases.
The StructuredMain method should define the test sequence only. The concrete tests should be
done in the test cases and test groups.
Event procedures are only active during test module execution (see also AN-IND-1-002 Testing with
CANoe).
The special CANoe mode does not allow accessing runtime values and invoking methods from
Vector.CANoe.Runtime, Vector.Tools, Vector.Scripting.UI,
Vector.CANoe.Threading and most of the methods in Vector.CANoe.TFS. For this they
cannot be called in the StructredMain() method.
It is not allowed to call CAPL test cases or test functions in the StructuredMain() method.
The execution sequence of the test cases in the module must be constant, e.g. a random
execution of test cases is not allowed and may lead to unexpected enabling / disabling states of
the test cases.
If you have a set of test cases that are randomly executed or that depend on the test verdicts
from other test cases you should encapsulate them in a method that is marked with a
[TestGroup] attribute. The body of such a method is also not executed during test module
analysis and the group can only be enabled / disabled as a whole. An example for this can be
found in the Central Locking Demo .NET of CANoe.
Verdict handling:
> TestStepFail(…) The teststep verdict will be set to ‘Fail’ and it is propageted to
the related test case and test module verdict.
> TestStepPass(…) A passed test step with additional information is written to the
report. The verdict is not changed.
> TestStepWarning(…) A warning is written to the report.
A complete list can be found in the CANoe help or in the type libraries that are referenced in your test
module solution.
The signal-oriented API in .NET is state-oriented. This means that if a wait point for a signal element is
used the wait condition is checked immediately and if the signal is already set (i.e. the condition is
met), the wait point also resumes immediately.
In contrast to the signal-oriented approach in .NET message-oriented approach is event-based.
More wait points are contained in the API. Please check the online help for further details.
5.2.4 Checks
Checks in .NET test modules are used to monitor certain system conditions during a test sequence.
There are three types of checks; Constraints, Conditions and additionally Observations.
Constraints are used to guarantee that the environment fulfills certain criteria and Conditions
supervise the behavior of the tested system. Any violation of these checks leads to a failing test case
and test module.
This is in contrast to Observations that cannot influence the verdict of a test module even though
violations are always included in the test report.
Checks can be active during a complete test sequence, a complete test case, or they can be
activated/deactivated using method calls.
The TFS provides several predefined checks
> Vector.CANoe.TFS.ValueCheck is used to monitor the value criteria of bus signals, environment
and system variables
> Vector.CANoe.TFS.AbsoluteCycleTimeCheck, Vector.CANoe.TFS.RelativeCycleTimeCheck and
Vector.CANoe.TFS.OccurenceTimeCheck check the timing of messages
> Vector.CANoe.TFS.DlcCheck monitors the message length indication
The class ValueCheck represents a simple check for the value of a signal, environment variable or
system variable. Here the value of the signal EngineRunning is checked:
[TestCase("Title", "Description")]
public void ObserveEngineState()
{
ICheck engOn = new ValueCheck<EngineRunning>(CheckType.Observation, 1);
engOn.Activate();
Vector.CANoe.Threading.Execution.Wait(4000); // observation active
engOn.Deactivate();
}
This is an example of checking the value of a bus signal. First the check for the signal value is created
with the type Condition for the value ‘1’. Then the check is activated, and after a 4s wait the check is
deactivated before the test case end.
A cycle time check for a message is done like this. The activation is done as in the previous example.
ICheck check = new AbsoluteCycleTimeCheck<NetworkDB.Frames.CyclicMsg>
(CheckType.Condition, 80, 120);
If user-defined system conditions should be checked, a customized class can be defined (e.g. for DLC
observation):
5.2.5 Criterions
Criterions can be used
> to wait until system conditions are reached
> to observe system conditions
The Criterion attribute can be used to define a handler to be used within checks or wait points
[Criterion]
[OnChange(typeof(AntiTheftSystemActive))]
[OnChange(typeof(LockState))]
bool AntiTheftSystemCriterion()
{
if((EngineRunning.Value == 0) && (LockState.Value == 1))
return (AntiTheftSystemActive.Value == 1);
else
return (AntiTheftSystemActive.Value == 0);
}
Apply the criterion above in a Check – the check fails, if the criterion handler returns false:
Check observeAntiTheftSystem = new Check(AntiTheftSystemCriterion);
observeAntiTheftSystem.Activate();
Apply the criterion above in as Wait Point condition – the wait point is resumed, if the criterion handler
returns true:
Execution.Wait(AntiTheftSystemCriterion);
Note1: The handler was immediately called on setup of the wait or the check to handle the start
condition.
Note2: Handlers that are marked with the Criterion attribute are only active while the check or wait
condition is active.
The Criterion class can be used to combine several single criterions to a complex criterion, e.g. when
several signal values have to be checked in parallel. This is similar to the testJoinAuxEvent()
function in CAPL.
Criterion antiTheftSystem = new Criterion();
antiTheftSystem.AddMandatory(new ValueCriterion<AntiTheftSystemActive >(0));
antiTheftSystem.AddOneOf(new ValueCriterion<LockState>(0));
antiTheftSystem.AddOneOf(new ValueCriterion<EngineRunning>(1));
Again the combined criterion can be used I a check – the check is failed, if a mandatory condition is
violated or if all optional conditions are violated:
Check observeAntiTheftSystem = new Check(antiTheftSystem);
observeAntiTheftSystem.Activate();
And also as a wait condition – the wait point is resumed, if if all mandatory conditions are fulfilled and
if one optional condition is fulfilled:
Execution.Wait(antiTheftSystem, 1000);
[Expected(typeof(NetworkDB.LockState), Relation.Equal)]
public double lockState = 0;
}
The created test pattern can now be used in a test case, e.g. by applying the Execute() method on it:
[TestCase]
public void LockStateDependsOnCrashDetection()
{
// Test Pattern - Crash Detection function test
CrashDetectionTest crashTest = new CrashDetectionTest();
crashTest.Execute();
// Change test pattern input parameter and re-execute
crashTest.crashDetected = 0;
crashTest.Execute();
}
The service and parameter qualifier can be copied from the CANoe symbol explorer.
More background information can be found in ‘VDS_Library_QuickStart.pdf’ that is available in the
CANoes start menu / Help / ‘Documentation Vector Diagnostic Scripting Library’.
6.0 Migrating a .NET Module that was created with CANoe < 7.6SP3
When a .NET module (network node, test node or test library) is created with CANoe < 7.6SP3 the
solution contains absolute path references to the CANoe .NET API.
When you change to CANoe 7.6SP3 or newer these references and assemblies have to be updated
with the actual ones that contain a link to the used CANoe installation:
• Remove the solution (*.sln) and the project (*.csproj) files for your module from your CANoe
configuration folder. If the solution or project has user defined settings they have to be redone.
• In CANoe start editing the .NET module. A new solution with all needed references is created
for the module. As a precondition you should configure the new CANoe version to use Visual
Studio as editor, see also chapter 3.1.
7.2 Concurrency
Although there can be several test modules running in parallel, these modules are not executed in
separate threads. This means you don't have to be concerned with synchronization mechanisms.
While a test module is waiting for an event, other test modules or CAPL code are carried out. This is a
form of cooperative multitasking; for this reason you should make sure not to program long running
operations in a test module without using intermediate Wait calls.
Because of the CANoe internal concurrency architecture, you are not permitted to use synchronization
primitives (such as locks) or start additional threads in a .NET program.
If you need to execute potentially long lasting operations you can use the CANoe WaitForTask
function. It is also possible to use the System.Thread class. In both cases only a very limited number
of API-functions are available in background threads:
Note: If class System.Thread is used, the user code is responsible for the exception handling. In
contrast to chapter 7.6, a catch on the base class System.Exception must be used here.
When the .NET module has been built with CANoe there is normally no debugging information
available and you should first rebuild the assembly with enabled debug mode in the IDE or you can
enable .Net Debugging in CANoe in Options dialog (menu: Configuration | Options | Programming |
.NET Debugging | .NET Debugger)
In case you debug your module in CANoe’s simulation mode it is useful to enable ‘windows timer’ in
Options dialog (menu: Configuration | Options | Measurement | General | Simulation | Use Windows
timer).
For detailed information on how the debugger should be attached, please refer to the Visual Studio
documentation.
7.4 Post-compilation
CANoe uses a PostCompilation step to add CANoe specific behavior to the .NET assemblies. Source
code containing the Attributes TestCase, TestFunction, Signal,,KeyboardHandler, TimerHandler,
TimerHandler etc. are enriched with additional code sequences used for e.g. test control, error
handling, reporting features.
The post compilation of the .NET assemblies is done by CANoe for all kinds of .NET modules. The
post compilation of the .NET assemblies is usually done in the Visual Studio build process, if the
project was created by CANoe. This is the recommended way of post compliation.
However CANoe checks .NET modules to ensure they are post compiled before using them. So a post
compilation step is automatically added in CANoe compile, if required.
To manually check if your .NET assembly is post compiled check an included resource:
public resource Vector.PostCompiler.Interface.IsPostCompiled
7.5 Troubleshooting
This warning can occur if the test case library was not post-compiled (see section 7.4).
7.5.4 Visual Studio cannot build because annother process holds the .NET assembly
Sometimes the RuntimeKernel.exe holds the assemblies after the measurement has been ended.
This problem can occur if the .NET solution/source file was created manually (i.e. not automatically by
CANoe). If the file was created manually the problem can be fixed by adding the following in Pre-build
event command-line in Visual Studio:
"$(CANoe_InstallDir)Scripts\ReleaseDotNetAssemblies.vbs" "$(SolutionPath)"
A new solution with correct settings can be created by deleting the old solution and editing the node.
CANoe creates a solution with all needed API references and commands.
Example:
[TestClass]
public class TestCaseLibrary
{
[Export] [TestCase] [BreakOnFail(true)]
public static void TestWithOwnExceptionHandling()
{
try
{
//Do something you need exception handling
…
}
catch(MyConcreteException)
{
//Do something inside your catch-block
…
}
}
9.0 Contacts
For a full list with all Vector locations and addresses worldwide, please visit http://vector.com/contact/.