ghorwin / FMICodeGenerator

A Code Generator that creates native C/C++ code to build Functional Mock-Up Units (FMU) with support for FMI version 2.0 (rollback)
BSD 3-Clause "New" or "Revised" License
51 stars 25 forks source link

execute other binary file in P_control.cpp #55

Closed xlxwzybds closed 2 months ago

xlxwzybds commented 2 months ago

Hi Sir ,

Your tool has greatly facilitated my understanding of the FMU construction process, thank you.

I am currently having trouble with how the FMU internal.so library calls FMU internal script files. My FMU file path is as follows:

fmu
├── binaries
 │   └── linux64
 │       └── P_Control.so
 │       └── main
├── modelDescription.xml

my code in P_control.cpp want to call binary execution file "main" , as below

 //TODO
    char command[100];
    snprintf(command , sizeof(command) , " ./main 1 2 " );
    int result = system(snprintf);
//TODO end

But no matter what I do, I can't find the right path to main inside FMU。 I know this should be a problem with my method, but I can't find the solution or relevant keywords. I'd like to get some advice from you.

Jiayan

ghorwin commented 2 months ago

Hi Jiayan,

the working path, or the path, where the FMU is being extracted to, depends on the Master programm. For example, if you use my Co-Simulation-Master (see https://bauklimatik-dresden.de/mastersim/), there you get the option of specifically defining a data/resource directory for access from within the FMU. There may be such a possibility in other FMU masters as well, but you'll have to check.

Otherwise, you may always use hardcoded full paths in your FMU - this may not be portable, but works.

All the best, Andreas