- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Use of Records in external C code
Page Start Prev 1 Next End
Use of Records in external C code
Use of Records in external C code
Oct-04-21 18:32:31
Hello,
I created a small test example for using a modelica record in external C functions. My goal is to initialise the record in Modelica and hand it over to C by reference. Since the reference is in C I would assume, that data changes also for Modelica. Unfortunately this is not the result of my test example.
My C code is the following:
Code:
typedef struct
{
double a, b, c;
}threeValues;
void add_c(void*);
void add_c(void* in){
threeValues* out = (threeValues*)in;
out->a += 2.;
out->b += 2.;
out->c += 2.;
}
The modelica Code is:
Code:
model structTest
threeValues abc(a(start=1.), b(start=2.), c(start=3.));
record threeValues
Real a, b, c;
annotation(
Icon(coordinateSystem(extent = {{-200, -200}, {200, 200}})),
Diagram(coordinateSystem(extent = {{-200, -200}, {200, 200}})));
end threeValues;
function add
output threeValues abc;
external "C"
add_c(abc) annotation(
IncludeDirectory = "modelica://structTest",
Include = "#include \"add_two.c\"");
annotation(
Icon(coordinateSystem(extent = {{-200, -200}, {200, 200}})),
Diagram(coordinateSystem(extent = {{-200, -200}, {200, 200}})));
end add;
equation
abc = add();
annotation(
Icon(coordinateSystem(extent = {{-200, -200}, {200, 200}})),
Diagram(coordinateSystem(extent = {{-200, -200}, {200, 200}})));
end structTest;
I already tested various variants, e.g. with algorithm section, but the data in Modelica is either Nan or fix at the initial values.
Has somebody an idea what I am doing wrong?
Page Start Prev 1 Next End
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Use of Records in external C code
There are 0 guests and 0 other users also viewing this topic