Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

How to Export a FMU as C# ( Csharp ) ?

How to Export a FMU as C# ( Csharp ) ?

Hi,

iam new in this community and want to learn to work with modelica. My first project idea was to connect a robot model with my Robot in Solidworks, to simulate the Robot while turning in my motion study in Solidworks.

Therefor i need to export the Modelica-Model in C#. I saw its possible to export as C-Code, but when i change the target language i get this error:

------------------------------------------------------------------------------------------------------

[27] 13:18:18 Übersetzung Fehler
Interner Fehler Unknown FMU template target: CSharp

[28] 13:18:18 Übersetzung Fehler
Interner Fehler SimCode: The model testrob could not be translated to FMU

------------------------------------------------------------------------------------------------------


What setting do i need to export the FMU as CSharp?




The next question is, how can i work with the exported model-Code. I saw the Exporter exports a "main.c" file, but i didnt got how i can start the model and get any output?!

Does any one of you exported a Model and used it in a code? Maybe i start a 2. thread but i first need the Csharp files to test it with my Solidworks-Addin.


Best regards,
Simon Fritz

Edited by: Fritz - Jun-14-16 11:42:46

Re: How to Export a FMU as C# ( Csharp ) ?

FMI is a binary format specifying C linkage. So all FMUs regardless of language used will import in the way (unless you use source-code FMUs which we do not do for C#; we also do not do FMI export using C#). My guess is that you just need an FMI master written in C# and load the FMU from that at run-time.

Re: How to Export a FMU as C# ( Csharp ) ?

thx for your quick reply!

Could you help me get started by coding a FMI master? I started working with modelica this week so i have no clue how to do this current/big_smile Or do you know a good tutorial how to code a FMI master?

Thx!

Simon

Re: How to Export a FMU as C# ( Csharp ) ?

Go to fmi-standard.org and read the documentation very carefully. That + Google weird errors importing dll's should tell you everything you need to know.

Re: How to Export a FMU as C# ( Csharp ) ?

ok ill try! Thx!

Re: How to Export a FMU as C# ( Csharp ) ?

do you know any code examples? Maybe in C or C++? Would help me a lot, cause the documentation doesnt gives a quick introduction in coding a FMI master^^

Re: How to Export a FMU as C# ( Csharp ) ?

Try the FMU SDK or FMI Library: https://fmi-standard.org/downloads

Re: How to Export a FMU as C# ( Csharp ) ?

-

Edited by: Fritz - Jun-21-16 07:11:42

Re: How to Export a FMU as C# ( Csharp ) ?

I found a easier solution for my problem. I use the ".exe" file to simulate. I just have the problem that i didnt found a way to read the results from the ".mat" file with C#.

I found this library but its only for Matlab 5 Files... and it doesnt work for the modelica results (Matlab 4)

http://www.mathworks.com/matlabcentral/ … or-net-2-0


Does anyone has a idea to read the result files without matlab in C#?

Re: How to Export a FMU as C# ( Csharp ) ?

The mat4 format is very simple, the reader is quite short: https://github.com/OpenModelica/OMCompi … _matlab4.c

Re: How to Export a FMU as C# ( Csharp ) ?

Hm... ok if there is no C# version ill try to translate it ^^

Thanks a lot!! current/smile

Edited by: Fritz - Jun-21-16 08:00:33

Re: How to Export a FMU as C# ( Csharp ) ?

hm... ok not that easy but ill get help tomorrow of a friend of mine, he knows c++.

Edited by: Fritz - Jun-21-16 11:46:35

Re: How to Export a FMU as C# ( Csharp ) ?

Efficiency reasons. Reading mat-files is easier than parsing csv, I promise. But yes, you can change output format to csv. Just specify -r outfile.csv when calling the simulation executable or choose csv from OMEdit or call https://openmodelica.org/doc/OpenModeli … ionresults to convert from mat to csv.

Re: How to Export a FMU as C# ( Csharp ) ?

Ok i think ill go for the .csv Version. My Software is just a prototype so it must not be very efficient it just has to work^^

Thank you a lot current/smile

Edited by: Fritz - Jun-21-16 14:21:12
There are 0 guests and 0 other users also viewing this topic
You are here: