# How to build FMUSimulator and FMILibrary
-CMake GUI for generating Visual Studio project files from FMILibrary sources
+## Base FMILibrary
+
+To build the Visual Studio Solution files you need CMake.
+CMake is also used to build the base native FMILibrary.
+
+Note:
+This is not usually needed, you can use the existing build.
Remember to manually delete CMakeCache and CMakeFiles from FMILibrary/build/expatex/-folder
-NOTE:
+Follow the instructions provided by the Linux Dockerfile and linuxbuild.sh.
+In short:
+1) Download the desired FMILibrary source .zip
+2) Unzip in a location of your choosing
+3) Open terminal
+4) Change directory to where you want to build the output
+5) Run cmake from command-line and provide as the first argument the path to where you unzipped sources in step 2
+Optional) To make a debug version, add -DFMILIB_ENABLE_LOG_LEVEL_DEBUG=ON before the path to source
+6) In both debug and normal case, run "make" and "make install test" to verify the installation
+
+If the build succeeded, you should have .dll files which you can now copy to your win32 or win64 org.simantics.fmil.* projects.
+Specifically:
+fmu1_dll_cs.dll, fmu1_dll_me.dll, fmu2_dll_cs.dll, fmu2_dll_me.sll and fmilib_shared.dll
+Copy the corresponding "Debug" build files to the sub-directoryn "Debug" in the projects.
+
+## FMUSimulator
+
+When you have the Visual Studio files:
+Build from command-line our FMUSimulator.dll
+
+1) Open a terminal
+2) Navigate to org.simantics.fmil.core/native/FMUSimulator
+3) Run "msbuild.exe"
+
+## Building on linux
When building the libfmilib_shared.so, we need to replace fmi_util.c file under "<path to FMILibrary>/src/Util/src/FMI/fmi_util.c" with contents of fmi_util.c.txt, located
under /native/FMUSimulator/fmi_util.c.txt. The Dockerfile already does this so if you build the libfmilib_shared.so with that, then you needn't worry about this.
#include <vector>
#include <iostream>
#include <regex>
+#include <atomic>
#include <org_simantics_fmil_FMILJNI.h>
using namespace std;
+static std::atomic<int> instanceNameID;
+
+int create_id() {
+ return instanceNameID++;
+}
+
struct FMI1 {
void *fmu;
JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_instantiateSimulation_1
(JNIEnv *env, jobject obj, jint id) {
+ int uniqueId = create_id();
+ std::string instanceName = std::to_string(uniqueId);
int returnValue;
const char *error = "";
FMI1 &fmi = fmus[id];
if (fmi.version == 1) {
- returnValue = FMI1_CS_INSTANTIATE(fmi.fmu, "", &error);
+ returnValue = FMI1_CS_INSTANTIATE(fmi.fmu, instanceName, &error);
} else if (fmi.version == 2) {
- returnValue = FMI2_CS_INSTANTIATE(fmi.fmu, "", &error);
+ returnValue = FMI2_CS_INSTANTIATE(fmi.fmu, instanceName, &error);
}
if(returnValue != 0) {
string message = "No FMU loaded: ";
private boolean fmuLoaded = false;
public void loadFMUFile(String path) throws FMILException {
+ if (!Files.exists(Paths.get(path)))
+ throw new FMILException("File " + path + " does not exist");
+ if (!Files.isRegularFile(Paths.get(path)))
+ throw new FMILException("Path " + path + " is not a file");
+
synchronized(syncObject) {
if(fmuN % 2 == 0) {
}
}
- private native int loadFMUFile_(String path, String toDir);
+ private native int loadFMUFile_(String path, String toDir) throws FMILException;
/**
* Set a step length for simulation