I have a small code in C that I want to use to call the IMF functions of fmu_sdk
in order to be able to export my model in FMU.
If you could tell me how the functions I need to use, here is my program:
best regards Mary
I have a small code in C that I want to use to call the IMF functions of fmu_sdk
in order to be able to export my model in FMU.
If you could tell me how the functions I need to use, here is my program:
best regards Mary
#include <stdio.h>
#include <stdlib.h>
#define vrai 1
#define faux 0
typedef enum BOOLEAN {false, true} bool;
bool function_ET(bool e1,bool e2);
int main(){
bool e1;
bool e2;
bool s;
printf("entrez les valeur de e1 et e2:");
scanf("%d%d",&e1 ,&e2);
s = function_ET(e1,e2);
printf("s = %d",s);
}
bool function_ET(bool e1,bool e2){
return(e1 & e2);
}
I was able to write the code C, but I did not manage to have the good result, I can not increment the values of e1 and e2, the values do not change with time, if you could m Help you write the exact code
#define MODEL_IDENTIFIER prog_entree1
#define MODEL_GUID "{8c4e810f-3da3-4a00-8276-176fa3c9f013}"
// define model size
#define NUMBER_OF_REALS 0
#define NUMBER_OF_INTEGERS 0
#define NUMBER_OF_BOOLEANS 3
#define NUMBER_OF_STRINGS 0
#define NUMBER_OF_STATES 0
#define NUMBER_OF_EVENT_INDICATORS 0
// include fmu header files, typedefs and macros
#include "fmuTemplate.h"
//#include "prog1entrée.c"
#define e1 0
#define e2 1
#define s_ 2
void setStartValues(ModelInstance *comp) {
b(e1) = 1;
b(e2) = 0;
}
void calculateValues(ModelInstance *comp) {
if (comp->state == modelInitializationMode) {
b(s_)= b(e1) && b(e2);
}
}
fmi2Boolean getBoolean(ModelInstance* comp, fmi2ValueReference vr)
{
switch(vr)
{
case e1 : return b(e1);
case e2 : return b(e2);
case s_ : return b(s_);
}
}
void eventUpdate(ModelInstance *comp, fmi2EventInfo *eventInfo, int
timeEvent, int isNewEventIteration)
{
}
// include code that implements the FMI based on the above definitions
#include "fmuTemplate.c"
And the result I got after the simulation enter image description here
Do you want to create a model exchange or co-simulation FMU?
Here is a link to a model-exchange FMU that implements an AND for two boolean input values (FMI 2.0, win64): https://www.dropbox.com/s/su8pyjdtg4hs7v1/fmu_boolRef.fmu?dl=0 And here a link to a co-simulation FMU: https://www.dropbox.com/s/bcbl8tf6xb4jc8x/fmu_boolRef.fmu?dl=0
You can compile the the contained source code also to a co-simulation FMU.