在 fmu_sdk 中使用 FMU

using the FMU in fmu_sdk

我在 C 中有一个小代码,我想用它来调用 fmu_sdk 的 IMF 函数,以便能够在 FMU 中导出我的模型。

如果你能告诉我我需要如何使用这些功能,这是我的程序:

此致 玛丽

  #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);
}

我能写出C代码,但没能得到好的结果,我不能增加e1和e2的值,值不随时间变化,如果你能m帮助你写出准确的代码

#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"

以及我模拟后得到的结果 enter image description here

您要创建模型交换或联合仿真 FMU 吗?

这是一个模型交换 FMU 的 link,它为两个布尔输入值(FMI 2.0,win64)实现了 AND:https://www.dropbox.com/s/su8pyjdtg4hs7v1/fmu_boolRef.fmu?dl=0 这里 link 到联合仿真 FMU:https://www.dropbox.com/s/bcbl8tf6xb4jc8x/fmu_boolRef.fmu?dl=0

您也可以将包含的源代码编译为联合仿真 FMU。