Tutorial: Export an Embed Block from Twin Activate

Export generated code both for simulation and inclusion of generated code in Embed for target deployment purposes.

Attention: Available only with Twin Activate commercial edition.

Prerequisites for This Tutorial

The following software is required for this tutorial:

  • Altair Twin Activate
  • Altair Embed
  • Visual Studio Compiler for compiling generated code from Twin Activate and to create an Embed block.

Overview

One of Twin Activate's code generation options is to export the generated code both for simulation and inclusion of generated code in Embed for target deployment purposes. This tutorial captures the overall steps to set up and achieve a working setup for such a design flow.

Embed provides standard block APIs to define the block behavior for simulation and code generation. The code generation option Embed Block leverages these published APIs to automatically wrap the generated code from Twin Activate.

When creating a simulation diagram in the Twin Activate diagram, you can easily test the generated code in a target environment. The code is target agnostic and optimized, leveraging the inlined code generation option. Embed supports more than 1200 microcontroller targets. You can include the needed target specific drivers and schedule for execution using the visual interface from Embed. You can also customize the RTOS behavior and Software/Hardware Interrupt scheduling in Embed for testing in Processor In the Loop and Hardware In the Loop configurations.

Export an Embed Block

In this tutorial, a standard Twin Activate demo is used, but the process should be the same across any other diagrams. A super block can be exported as an Embed Block if the contents are supported by the inlined code generator. An exhaustive updated list of blocks supported by the inlined code generator can be found in Extended Definitions.
  1. In a Twin Activate diagram, select the super block to be exported.
  2. Select Export > Export from the menu ribbon.
    You can also right-click on the super block and select Code Generation and Export.
  3. Set Target to be Embed Block. Set Processor to 64 bits or 32 bits, depending on your Embed installation. Select the Embed installation path and your desired Output directory. Set the other name fields as necessary.
  4. Click Generate.
    In the output directory, you now have the following files:
    • Body.c: A C file that provides the implementation of the actual super block.
    • Body.h: Header file containing the function definition for the implementation in the Body.h.
    • main.cpp: Embed Block Specific Wrapper with the Body.h file to include the relevant generated code from Twin Activate. The file contains functions leveraging the Embed Block API for simulation and code generation.
    • make.bat and make.sh: Contains the relevant make process for the generated code.
      Note: Based on the Embed installation, relevant libraries (Vissim32.lib/Vissim64.lib) are referenced for linking.
    • [DLL name].def: Exported functions for the current diagram.
      Note: In the example from the above screenshot, this file name is Block_From_Activate.def.
    • [DLL name].dll: Compiled model for Embed.

Twin Activate Block in Embed

After the DLL has been created, it is automatically added to Embed.

In Embed, you can find the new block in Imported Blocks > Twin Activate.

Note: The new block keeps its location in the selected fields. You can remove it from Embed in Edit > Preferences.

You can use the new block for simulation and code generation.