0

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:

programm C

best regards Mary

Cristik
  • 30,989
  • 25
  • 91
  • 127
Mary13
  • 3
  • 2
  • Include your code here. Why would you upload it as a picture? – jAC Jul 06 '17 at 15:14
  • Hi and welcome to Stack Overflow, please read how to create a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and also check [How to Ask Good Questions](https://stackoverflow.com/help/how-to-ask) so you increase your chances to get feedback and useful answers. – DarkCygnus Jul 06 '17 at 16:53

3 Answers3

0
  #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);
}
Mary13
  • 3
  • 2
0

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

Mary13
  • 3
  • 2
0

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.

  • thank you for your reply,i want to create a co-simulation FMU bat i want in my fmu, the values of my inputs Will be incremented – Mary13 Jul 13 '17 at 08:18
  • thank you for your reply,i want to create a co-simulation FMU bat i want in my fmu, the values of my inputs Will be incremented : e1= 0? e2=0 ==> s_=0 / e1= 0, e2=0 ==> s_=0 / e1= 0, e2=1 ==> s_=0 / e1= 1, e2=0 ==> s_=0 /e1= 1, e2=1 ==> s_=1 – Mary13 Jul 13 '17 at 09:14
  • I added a link to a co-simulation FMU (FMI 2.0, win64 and source code) that should do what you want. Please note, that there is one timestep delay, as there is no direct feedthrough for co-simulation FMUs. – Christian Bertsch Jul 13 '17 at 20:18