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
  • Index
  • » Users
  • » kermit_d
  • » Profile

Posts

Posts

Feb-02-13 23:18:33
Use model as external input/output

Finally i've got the solution, maby not super elegant but still current/smile. So using dll was total failier, socket - ok but the includes file (socket.h,winsock2.h) are missing or it's not commatible with mingw of openmodelica.
I'll use a stdin and stdout (maby stderr) to comunicate with simultion. So i run in c# simulation using proccess, and redirect a stdout of simulation to my c# application current/wink From c# i can use socket and everythink what i want.
Thanks for help.

Jan-31-13 00:46:20
Use model as external input/output

sjoelund.se wrote:

External objects have a constructor function that is only called once in a simulation. when initial() may be called multiple times but is commonly used to call functions at the start of the simulation.

So i can make my own source (input/output) model which i'll just add to simulation and i'll don't have to change code manualy, and recompile it current/smile
Adding c code to it is no problem  ---- external "C" r=rnd(y) annotation(Include = "#include <rnd2.c>";  ---
, but how to add starting code to the constructor? And where is a description of external function?
i've read the https://www.modelica.org/documents/ModelicaSpec31.pdf.
So first i've to add include code with constructor, and next execute one of it's function whet simulation is in progress (in event or somethink)?

One more question, how to compile the model using gcc compiler, what is the formula in windows (gcc ?????????)

Ok, look what i found : https://openmodelica.org/svn/OpenModeli … pleClient/

I'll also need to change makefile to add -lwsock32 to compiler command line.

Jan-30-13 23:49:57
Use model as external input/output

Unfortunately the example isn't as good as i thought. It's reading input file and when something is in it he do the simulation based on value readed from that file.
So nevermind, i'll try to do scocket (tcp) comunication.
But i've got some questions :
-is it posiible to add c code (global function or values) at the begining (constructor or somethink like that) of the simulation? I know i can do it manualy by editing model.c file.
- how to stop the simulation? Is only solusion are endles loop whlie calculating (adding c function to model) or sample event which will don't stop the simulation?
- is it possible to change step size while simulation is in progres?

Jan-29-13 16:14:39
Use model as external input/output

Thanks current/smile this example is great. When i finish i'll write how it goes!

Jan-29-13 14:21:52
Use model as external input/output

probably, the other way to comunicate with simulation is to implement a socket(tcp) comunnication. Maby you know an example of that? Somebody try it?

Jan-29-13 14:17:29
Use model as external input/output

Ok i see. It's created a dll file. And the import functions are :

void setStartValues(ModelInstance *comp);
void setDefaultStartValues(ModelInstance *comp);
void eventUpdate(ModelInstance* comp, fmiEventInfo* eventInfo);
fmiReal getReal(ModelInstance* comp, const fmiValueReference vr);
fmiStatus setReal(ModelInstance* comp, const fmiValueReference vr, const fmiReal value);
fmiInteger getInteger(ModelInstance* comp, const fmiValueReference vr);
fmiStatus setInteger(ModelInstance* comp, const fmiValueReference vr, const fmiInteger value);
fmiBoolean getBoolean(ModelInstance* comp, const fmiValueReference vr);
fmiStatus setBoolean(ModelInstance* comp, const fmiValueReference vr, const fmiBoolean value);
fmiString getString(ModelInstance* comp, const fmiValueReference vr);
fmiStatus setExternalFunction(ModelInstance* c, const fmiValueReference vr, const void* value);

and that's the way to comunicate with simulation? All function describes are in https://www.fmi-standard.org/. Am i correct?

Jan-29-13 14:01:15
Use model as external input/output

Ok, what next?  How to create a dll( API C) from Functional Mockup Interface. Any guide or example?

Maybe i'll give more details:
- im using windows, so probably i'll have to create dll in MinGW compiler.
- i want to import a simulation using a dllimport in c#, set the simulation parameters an visualize the results.

Jan-29-13 01:26:17
Use model as external input/output

Hello!

Is there any way to compile model to dll, not exe? I'll try to create hardware in loop simulation. The plan is to use simulation as DLL file, import it in other program and using dll import function sets input and gets resault using exportable function.

best regards
Dominik

  • Index
  • » Users
  • » kermit_d
  • » Profile
You are here: