Monday, August 4, 2025

Accessing Automation Desk With XIL API via Python:

Quick Overview :

Replace the HIL API Python import directive with calls to clr.AddReference() (a command of the Python for .NET package), by using the required ASAM XIL API .NET assemblies.

Create a TestbenchFactory and a vendor-specific Testbench

Replace all HIL API Python constructor calls with the equivalent factory class call from the XIL API .NET.

Replace the code for HIL API MAPort creation using a configuration dictionary with code that uses the new XIL API concept for MAPort creation using a port configuration file. 


5 Migration Examples 

This section uses specific examples to show you step by step how to convert HIL API Python commands into the classes and method calls of dSPACE XIL API .NET. In each case, a short section of the HIL API Python code is compared to an equivalent section that uses XIL API .NET. 

5.1 Importing the XIL API .NET Assemblies 

For any .NET services and components, you have to import or reference the required assembly into the Python workspace

This requires the Python for .NET command clr.AddReference(). 


5.2 Using the .NET Framework  

XIL API .NET expects .NET data types. You therefore have to use them explicitly. The following example shows a .NET dictionary:


5.3 Creating dSPACE XIL API TestbenchFactory and Testbench 

XIL API .NET uses the factory pattern for creating all kinds of Testbench-specific objects. At first, you need to create a TestbenchFactory and a VendorSpecificTestbench:

 


In the next step, you have to create an instance of the MAPort class to access the values of the realtime application

The platform identifier as it appears in ControlDesk 4.x or later after successful registration

5.4 Creating and Configuring MAPorts  

In the XIL API, the configuration dictionary of the HIL API MAPort was replaced by a port configuration file


5.4.1 Example of a dSPACE XIL API MAPort Configuration File

you can access the real‑time application that is specified in the variable description file (SDF file) running on a modular system based on DS1005.

In the PlatformName key, you have to enter the platform name that you specified when you registered the platform.


  For details, refer to dSPACE XIL API Implementation Guide > Implementing an MAPort Application > Basics on the MAPort > Configuring the MAPort

5.5 Reading and Writing Values

while in HIL API a constructor was used, in XIL API a factory function of the Testbench's ValueFactory must be called instead. 



5.6 Measuring Variables

 Measure variables, the Start method of the Capture instance requires a capture result writer object to be passed as an argument

XIL API you have to replace the constructor of the capture result writer with a factory method of the capturing factory

The following example shows the creation of a CaptureResultMemoryWriter object using HIL API Python





5.7 Triggered Measurements 

Watcher objects used for triggering a measurement by using a WatcherFactory instead of constructors for the ConditionWatcher and the DurationWatcher objects. 


5.8 Creating Stimulus Signals  

To create the signals and symbols of the stimulus domain of the XIL API, use the SignalFactory and SymbolFactory classes instead of constructors. 




5.9 Generating Stimulus Signals 

All classes from the Common.SignalGenerator namespace are constructed via methods of the SignalGeneratorFactory class in the XIL API. 




6 Additional Information on Using dSPACE XIL API .NET in Python 

Typical HIL API Python script can be ported to XIL API .NET.

The following sections describe a few points in greater detail; points you must consider when using the dSPACE XIL API .NET server

6.1 Referencing the XIL API .NET assemblies 

.NET assemblies must be loaded to Python before you can use them.

This requires using the Python for .NET command clr.AddReference().

The following .NET assemblies are needed for using the dSPACE XIL API .NET server:
  •  ASAM.XIL.Interfaces.dll 
  • ASAM.XIL.Implementation.TestbenchFactory.dll 
For the above assemblies, the relevant Python code is:


Because the XIL API .NET assemblies are in the Global Assembly Cache (GAC), you do not have to specify path information. To determine the fully qualified assembly name, you can use Windows PowerShell with the following command:


6.2 Namespaces
In .NET, using namespaces is common. All classes of .NET frameworks are organized like this. The XIL API .NET is also divided into namespaces.

Example: In XIL API .NET, the TestbenchFactory class is located in the namespace ASAM.XIL.Implementation.TestbenchFactory.Testbench.

 In Python, you can create a new instance of the TestbenchFactory class as follows: 


You can use the import directive in Python so you do not have to write the complete namespace each time you create a new instance:

 
 6.3 Generic Collections from the .NET Framework
 This section shows you how to create such a dictionary, which is required for creating a XIL API ConditionWatcher.

The dictionary must have keys of the data type string; the values that are assigned to each key must also have the data type string.

For any class that belongs to the .NET Framework, the corresponding namespace needs to be referenced first before it can be used: 


6.5 Scaling Information in the Variable Description File

The variable description file defines whether a source value on a dSPACE platform

A specific parameter of some fixed point data type in the real-time application might be represented as a real world physical value in the test scenario. 

The dSPACE HIL API uses source values by default when reading, writing or capturing variables.

. For further information on scaling, refer to Software > Test Automation > dSPACE HIL API Implementations > dSPACE HIL API Python Implementation Document > Using dSPACE HIL API Python Implementation > Specific Enhancements to the HIL API Standard > Value scaling enable/disable via TRC file. 


With the dSPACE XIL API, the behavior changed to converted values. The scaling is enabled by default. This means that the value conversion is executed as specified by the scaling attribute in the variable description file

If this behavior is not desired, it can be disabled within the MAPort configuration file. For further information, refer to Software > Test Automation > dSPACE XIL API Implementations > dSPACE XIL API Reference > Model Access Port Implementation > MAPort Configuration > EnableScaling

 




Accessing Automation Desk With XIL API via Python:

Quick Overview : Replace the HIL API Python import directive with calls to clr.AddReference() (a command of the Python for .NET package), by...