Coupling the the behavior of your Application with other tools using AutoFOCUS3 (AF3)
Introduction
AF3 alone cannot satisfy all the needs of system development:
other tools are often needed, e.g., for modeling continuous behavior
(for the environment or for analog parts of a system),
for interoperability with legacy tools, or simply for using non-AF3 features in combination with AF3
(e.g., visualization).
In such cases, AF3 has cosimulation capabilities which allows to use AF3 simulation
with other tools in a synchronous manner.
This feature offers a web service interface that provides capabilities for other tools to follow and even manipulate a simulation of your AF3 model.
This section describes how to configure and start a cosimulation in your AF3 model, and how cosimulation can be accessed by other tools.
Creating a Cosimulation Specification
To use the cosimulation feature, you have to create a cosimulation specification for the component you want to cosimulate.
You can simulate either your entire component architecture or only some subcomponent.
To create a cosimulation specification for a component, open the context menu of the component and select "Cosimulation specification".
The Cosimulation Specification consists of two sections.
- General Section: to configure general properties of the web service interface that is published during a cosimulation.
- Type Representation Section: to configure how data and data types should be expressed in the web service.
General Section
In this section you can set the following attributes that are used to configure the web service.
- Service Host: Enter an IP address or a hostname on which the web service should be published. Make sure that the machine on which you run AF3 has access to the specified service host. The default value of this attribute is "localhost", which means that the cosimulation service will be published locally on your machine.
- Service Port: Enter a port number that specifies on which port of the service host the cosimulation service can be accessed. Make sure that the port number is valid and available on the service host. The default value of this attribute is "9999".
- Service Name: Enter a name for your web service. The default value of this attribute is "ws/cosimulation".
From these three attributes, AF3 forms a location to which the cosimulation web service will be published by the following rule:
http://<ServiceHost>:<ServicePort>/<ServiceName>
That means, in the default case, the service will be published to: http://localhost:9999/ws/cosimulation
Type Representation Section
The cosimulation web service exports simulation data from your AF3 model. Depending on how you want to use this data, it is sometimes necessary to configure the service in a way that the data is suitably exported.
In this section you can set the following attributes that are used to configure how simulation data and data types are represented in the web service.
- Representation of Boolean type: Enter a string that is used in the cosimulation web service to characterize a signal with a boolean data type. The default value of this attribute is "boolean".
- Representation of double type: Enter a string that is used in the cosimulation web service to characterize a signal with a double data type. The default value of this attribute is "double".
- Representation of integer type: Enter a string that is used in the cosimulation web service to characterize a signal with an integer data type. The default value of this attribute is "int".
- Accept "1" an "0" as valid boolean values?: Some tools encode boolean values true and false as "1" and "0". To avoid confusion with the use of "1" and "0" as integer values, the cosimulation by default does not accept numbers as boolean values. However, you may change this behavior by checking or unchecking this attribute.
- Separator used for double values: Enter a character that is used to separate the decimal number from the decimal places in the expression of a double value. The default value of this attribute is a "." (default for English number encoding). Especially for tools from Germany, you might want to change this separator to a "," .
Save the cosimulation specification after you made any changes by entering <Strg> + S or selecting File -> Save from the menu.
Running a Cosimulation
To start the cosimulation, right-click on the Cosimulation Specification element in the Model Navigator and select "Run Cosimulation".
AF3 now publishes the web service to the location specified in the cosimulation specification and switches to the Simulation Perspective.
The successful start of your web service is acknowledged by an information message popping up. After you have read it, you can simply close this message by clicking OK.
The Simulation Perspective is updated continously during the cosimulation, which means that you can watch and follow the behavior of your AF3 model even if it is completely controlled by another application.
Accessing a Cosimulation from another tool
While the cosimulation web service is running, you have access to AF3 simulation data from outside AF3. This includes information about the simulated model (e.g., inputs, outputs, data types), about the current simulation values, but also provides a possibility to manipulate the simulation from outside (e.g., by setting input values).
All the possible operations are specified in the Cosimulation Service that is introduced in the following.
The Cosimulation Service
The Cosimulation Service provides the following methods that can be called from outside AF3.
- Static methods:
- getInputPorts(): Returns the names of all input ports.
- getOutputPorts(): Returns the names of all output ports.
- getPortType(portname): Returns the type name of the port with the given portname.
- getInitialValue(portname): Returns the initial value of a port with the given portname.
- Dynamic methods:
- calculate(): Performs a simulation step in AF3.
- getCurrentValue(portname): Returns the current value of a port with the given portname.
- setCurrentValue(portname,value): Sets the value, given as a string, of a port with the given portname.
- reset(): Resets the simulation to its initial conditions.
All data that that the web service takes or provides is encoded as simple Strings.
How to access the web service from another tool depends on the programming environment of the specific tool.
Here are some links to well known environments: