AHDL in C
You can build your own blocks in C using Microsoft Visual C++ version 4.2 or higher.
A template is provided which models a first order differential equation, like described in the manual. The example standardml.csi, which is provided for this template calls the modeling language file standardml.dll three times and the results are compared with the results from an INF block.
You can run this example from the debugger and also put breakpoints in the source code, to debug your modeling language.
In the above figure a breakpoint is inserted when t exceeds 5seconds
The code for the above example is in the template standardml.c. Open this template by opening the standardML.mdp project workspace file. If you want to use the debugger, place you simulation file in the same directory as standardML.dll in debug mode is created. This is mostly in the debug directory, although you can change this in the options for the compiler.
If you run the example from another directory where another standardML.dll is already present, the debugger will not work correctly. Remove the old standardML.dll file, before compiling a new version and debugging it in the compiler.
You can use this temple (standardML.c and standardML.def) for defining your own C-code dlls. The template contains the correct function calls and prototypes.
If you want to create a new C-code dll, start Visual C++ and select File/New
Select ‘Project Workspace’ and select [OK]. This will invoke a new project. Select [Dynamic Link Library]
Type the directory where you want to have the files installed at: "Location:", for example, "d:/caspoc2001/MyC"
Type the name of the project file at "Name:", for example, "MyC" and click [Create].
Open the explorer and copy the templates standardML.c and standardML.def to your newly created directory. Rename them to the same name as the project file for convenience, for example, "MyC.c" and "MyC.def"
Include these two files in your project by selecting Insert/Files into Project. Select All Files (*.*) at [Files of type]. Select the *.c and the *.def files, for example, MyC.c and MyC.def
Select [Add] to include the files in your project workspace. By double clicking the files folder in the left window, you can select the *.c or the *.def files for editing. The exported function should be specified in the *.def file.
The dll, which you use during debugging, should not be used as final release. Therefore the ‘Release’ option can be set. This Release version, which runs without debugger is much faster. Set the [Release] compile option for creating your final dll in the toolbar ‘Project’.
Select Win32 Release
In the project settings [Build/Settings], (ALT-F7), you can specify where the *.dll is created.
The function:
int ML_C(void){return 1;}
has to be defined to let Caspoc know that this is a C file and not a Delphi file.
#include <windows.h> |
LIBRARY StandardML |