NTNU-IHB / FMI4cpp

FMI 2.0 implementation written in modern C++.
MIT License
93 stars 34 forks source link

Is there any detail about api ? #115

Closed aoxipo closed 2 years ago

aoxipo commented 2 years ago

Hello! thank your for your contribute !!!! i want to know is there any doc for api interface? i‘m try to print the fmu object val like “my_var” and change it ,but i can’t find any api to change the value 。

markaren commented 2 years ago

There is no documentation. The API should be quite straightforward to intuitively understand. It is also heavily object oriented so the IDE should give you a hand. It is also pretty similar to the FMI API, although get/set is called read/write.

For reading and writing, see: https://github.com/NTNU-IHB/FMI4cpp/blob/master/include/fmi4cpp/fmu_variable_accessor.hpp

An FMU instance inherits from fmu_variable_accessor.

aoxipo commented 2 years ago

Think you for your help !

aoxipo commented 2 years ago

Hello,can you provide a demo like change the value about “my_var”? i 'm noob in C++ , I found the fmu_write/fmu_read and write/read but i dont know how to use it this is my code

    auto var = cs_md->get_variable_by_name('my_var').as_real();
    fmi2ValueReference attar_reference = var.valueReference();
    fmi4cpp::fmi4cppReal float_value = value;
    var.write(fmu_writer::write_real(attar_reference, value), float_value);
markaren commented 2 years ago
auto fmu = fmi2::fmu("path/to/fmu.fmu").as_cs_fmu();

auto md = fmu->get_model_description();
auto var = md->get_variable_by_name("my_var");

auto slave = fmu->new_instance();
slave->setup_experiment();
slave->enter_initialization_mode();
slave->exit_initialization_mode();

double value = 1.0;
slave->write_real(var.valueReference(), value);

Please try not not to use the issue tracker for help requests. You might want to use a different library with more docs and users. I provide this code with no support.

aoxipo commented 2 years ago

OK,i understand, think you for your help!