Object based program API¶
The object based program API is designed to read, create or modify ecu.test relevant files. With it you can create your own scripts in a Python development environment of your choice. The design follows an object oriented approach. To execute your script, a started ecu.test is needed.
To use it from an external Python, please extend your PYTHONPATH to include
<path to program>\Templates\ApiClient in order to be able to import it as
shown in the example below. The ApiClient is Python 2 and Python 3 compatible.
To use the Object API from within ecu.test use api.ObjectApi
Info
The Object API is for dealing with ecu.test relevant files only, e.g. Packages, Projects, TBC or TCF. If you want to execute test cases, you need to use the REST API or the COM API.
Examples for coding with the Object API can be found here: Code Examples Object API
Java-Client¶
It is also possible to use the API in Java the same way as in Python. Please use the
ApiClient-X.Y-SNAPSHOT.jar from the same directory for that. (where X and Y are the
major and minor version of your ecu.test installation) Please note, default arguments are
not supported. Instead of the Python value None, the Java value null must be
used / will be returned.
The following snippet is the same example translated in Java.
On a command line one can use javac -cp ApiClient-X.Y-SNAPSHOT.jar ApiClientExample.java
to compile and java -cp .;ApiClient-X.Y-SNAPSHOT.jar ApiClientExample to run the example.
import de.tracetronic.tts.apiClient.stubs.*;
public final class ApiClientTest {
public void testTcf() {
String tcfFile = "C:\\Data\\ECU-TEST\\Configurations\\Testconfiguration.tcf";
ApiClient api = new ApiClient();
TestConfiguration tcf = api.ConfigurationApi.OpenTestConfiguration(tcfFile);
Model model = tcf.Platform.ModelAccess.Get("Plant model");
model.SetFile("NewModelFile.mdl");
tcf.Save(tcfFile);
}
public void testPackage() {
String packageFile = "C:\\Data\\ECU-TEST\\Packages\\Testpackage.pkg";
ApiClient api = new ApiClient();
Package testPackage = api.PackageApi.OpenPackage(packageFile);
for (TestStep ts : testPackage.GetTestSteps()) {
if (ts instanceof TsRead) {
TsRead tsCasted = (TsRead) ts;
if (tsCasted.GetExpectationExpression() == "abs(3 - value) <= 0.5") {
tsCasted.SetExpectationExpression("abs(3 - value) <= 1");
}
}
}
testPackage.Save(packageFile);
}
public static void main(String[] args) {
ApiClientTest client = new ApiClientTest();
client.testTcf();
client.testPackage();
}
}
DotNet-Client¶
It is also possible to use the API in C# and Visual Basic .Net the same way as in Python. Please
add a reference to the ApiClient.dll for that. It can be found in the same directory as
the Python and Java client. Instead of the Python value None, the C# value null or the
Visual Basic value Nothing must be used / will be returned.
The following snippet is the example translated to C#.
using TraceTronic.ObjectApi.stubs;
namespace ApiTest
{
class Program
{
public static void TestTcf()
{
string tcfFile = "C:\\Data\\ECU-TEST\\Configurations\\Testconfiguration.tcf";
if (!System.IO.File.Exists(tcfFile))
{
Console.WriteLine($"File path '{tcfFile}' does not exists! Abort.");
return;
}
ApiClient api = new ApiClient();
TestConfiguration tcf = api.ConfigurationApi.OpenTestConfiguration(tcfFile);
Model model = tcf.Platform.ModelAccess.Get("Plant model");
model.SetFile("NewModelFile.mdl");
tcf.Save(tcfFile);
}
public static void TestPackage()
{
string packageFile = "C:\\Data\\ECU-TEST\\Packages\\Testpackage.pkg";
if (!System.IO.File.Exists(packageFile))
{
Console.WriteLine($"File path '{packageFile}' does not exists! Abort.");
return;
}
ApiClient api = new ApiClient();
Package testPackage = api.PackageApi.OpenPackage(packageFile);
foreach (TestStep ts in testPackage.GetTestSteps())
{
if (ts is TsRead tsCasted)
{
if (tsCasted.GetExpectationExpression() == "abs(3 - value) <= 0.5")
{
tsCasted.SetExpectationExpression("abs(3 - value) <= 1");
}
}
}
testPackage.Save(packageFile);
}
static void Main(string[] args)
{
TestTcf();
TestPackage();
}
}
}
The following snippet is the example translated to Visual Basic .Net.
Imports TraceTronic.ObjectApi.stubs
Module Module1
Sub TestTcf()
Dim tcfFile As String = "C:\\Data\\ECU-TEST\\Configurations\\Testconfiguration.tcf"
Dim api As New ApiClient()
Dim tcf As TestConfiguration = api.ConfigurationApi.OpenTestConfiguration(tcfFile)
Dim model As Model = tcf.Platform.ModelAccess.Get("Plant model")
model.SetFile("NewModelFile.mdl")
tcf.Save(tcfFile)
End Sub
Sub TestPackage()
Dim packageFile As String = "C:\\Data\\ECU-TEST\\Packages\\Testpackage.pkg"
Dim api As ApiClient = New ApiClient()
Dim testPackage As Package = api.PackageApi.OpenPackage(packageFile)
For Each ts As TestStep In testPackage.GetTestSteps()
If TypeOf ts Is TsRead Then
Dim tsCasted As TsRead = CType(ts, TsRead)
If tsCasted.GetExpectationExpression() Is "abs(3 - value) <= 0.5" Then
tsCasted.SetExpectationExpression("abs(3 - value) <= 1")
End If
End If
Next
testPackage.Save(packageFile)
End Sub
Sub Main()
TestTcf()
TestPackage()
End Sub
End Module
API entry points¶
Part of the Object based program API.
- class ApiClient¶
Entry point for object based api.
- AnalysisJobApi¶
Returns the AnalysisJobApi namespace
- Returns:
AnalysisJobApi namespace
- Return type:
- ArtifactApi¶
Returns the ArtifactApi namespace.
- Returns:
ArtifactApi namespace
- Return type:
- ConfigurationApi¶
Returns the ConfigurationApi namespace.
- Returns:
ConfigurationApi namespace
- Return type:
- GlobalMappingApi¶
Returns the GlobalMappingApi namespace.
- Returns:
GlobalMappingApi namespace
- Return type:
- MultimediaApi¶
Returns the MultimediaApi namespace.
- Returns:
MultimediaApi namespace
- Return type:
- PackageApi¶
Returns the PackageApi namespace.
- Returns:
PackageApi namespace
- Return type:
- ParameterApi¶
Returns the ParameterApi namespace.
- Returns:
ParameterApi namespace
- Return type:
- ProjectApi¶
Returns the ProjectApi namespace.
- Returns:
ProjectApi namespace
- Return type:
- RelationApi¶
Returns the RelationApi namespace.
- Returns:
RelationApi namespace
- Return type:
- SignalDescriptionApi¶
Returns the SignalDescriptionApi namespace.
- Returns:
SignalDescriptionApi namespace
- Return type:
- TraceFileApi¶
Returns the TraceFileApi namespace.
- Returns:
TraceFileApi namespace
- Return type:
- TraceStepTemplateApi¶
Returns the TraceStepTemplateApi namespace.
- Returns:
TraceStepTemplateApi namespace
- Return type:
- WorkspaceApi¶
Returns the WorkspaceApi namespace.
- Returns:
WorkspaceApi namespace
- Return type:
- GetApplicationVersion()¶
Returns the version of ecu.test in format ‘year.release.servicepack’.
- Returns:
ecu.test version
- Return type:
str
- GetClientVersion()¶
Returns the version of the object based api client.
- Returns:
client version
- Return type:
str