2 Copyright (C) 2012 Modelon AB
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the BSD style license.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 FMILIB_License.txt file for more details.
12 You should have received a copy of the FMILIB_License.txt file
13 along with this program. If not, contact Modelon AB <http://www.modelon.com>.
18 #include "fmi_dll_1_0_cs.h"
19 #include "fmi_dll_1_0_me.h"
20 #include "fmi_dll_common.h"
22 #include "fmi_zip_unzip.h"
23 #include <FMI1/fmi1_xml_model_description.h>
24 #include "fmi_import_util.h"
27 #define PRINT_MY_DEBUG printf("Line: %d \t File: %s \n",__LINE__, __FILE__)
29 void mylogger(fmiComponent c, fmiString instanceName, fmiStatus status, fmiString category, fmiString message, ...)
33 va_start(argp, message);
34 vsprintf(msg, message, argp);
35 if (!instanceName) instanceName = "?";
36 if (!category) category = "?";
37 printf("fmiStatus = %d; %s (%s): %s\n", status, instanceName, category, msg);
48 int main(int argc, char *argv[])
50 fmiCallbackFunctions callBackFunctions;
52 const char* FMUPath = "C:\\P510-JModelica\\FMIToolbox\\trunk\\src\\wrapperfolder\\Furuta.fmu";
53 const char* tmpPath = "C:\\Documents and Settings\\p418_baa\\Desktop\\XMLtest\\temporaryfolder";
55 const char* modelIdentifier;
56 const char* modelName;
57 const char* model_description_path;
58 const char* instanceName;
60 fmi_dll_standard_enu_t standard = FMI_ME1; /* or FMI_CS1 */
64 fmiBoolean loggingOn = fmiTrue;
65 fmi1_xml_model_description_t* md;
66 jm_status_enu_t status;
70 if (jm_status_error == fmi_zip_unzip(FMUPath, tmpPath)) {
71 printf("Failed to unzip the FMU file\n");
75 callBackFunctions.logger = mylogger;
76 callBackFunctions.allocateMemory = calloc;
77 callBackFunctions.freeMemory = free;
79 model_description_path = fmi_import_get_model_description_path(tmpPath, callBackFunctions);
81 md = fmi1_xml_allocate_model_description(0);
85 if(fmi1_xml_parse(md, model_description_path)) {
86 printf("Error parsing XML file %s:%s\n", FMUPath, fmi1_xml_get_last_error(md));
87 fmi1_xml_free_model_description(md);
92 printf("Model name: %s\n", fmi1_xml_get_model_name(md));
93 printf("Model identifier: %s\n", fmi1_xml_get_model_identifier(md));
94 printf("Model GUID: %s\n", fmi1_xml_get_GUID(md));
96 modelIdentifier = fmi1_xml_get_model_identifier(md);
97 modelName = fmi1_xml_get_model_name(md);
98 GUID = fmi1_xml_get_GUID(md);
100 modelIdentifier = fmi1_xml_get_model_identifier(md);
104 dllPath = fmi_import_get_dll_path(tmpPath, modelIdentifier, callBackFunctions);
106 fmu = fmi_dll_common_create_dllfmu(dllPath, modelIdentifier, callBackFunctions, standard);
108 printf("An error occured while fmi_dll_common_create_dllfmu was called, an error message should been printed.\n");
113 status = fmi_dll_common_load_dll(fmu);
114 if (status == jm_status_error) {
115 printf("Error in fmi_dll_common_load_dll: %s\n", fmi_dll_common_get_last_error(fmu));
120 status = fmi_dll_common_load_fcn(fmu);
121 if (status == jm_status_error) {
122 printf("Error in fmi_dll_common_load_fcn: %s\n", fmi_dll_common_get_last_error(fmu));
127 printf("fmi_dll_1_0_me_get_version: %s\n", fmi_dll_1_0_me_get_version(fmu));
129 fmi_dll_common_free_dll(fmu);
130 fmi_dll_common_destroy_dllfmu(fmu);
132 fmi1_xml_free_model_description(md);
134 printf("Everything seems to be OK since you got this far=)!\n");