NTNU-IHB / PythonFMU

A lightweight framework that enables the packaging of Python3.x code as co-simulation FMUs
MIT License
133 stars 38 forks source link

matlab crashes when i use the fmu that is generated by pythonfmu #208

Closed a3678911 closed 7 months ago

a3678911 commented 7 months ago

this is my code, when i use it to generate fmu and run the fmu in matlab or ther software that can support fmi, matlab crashes. Why? ` from pythonfmu import Fmi2Causality, Fmi2Slave, Boolean, Integer, Real, String

class PythonSlave(Fmi2Slave): author = "John Doe" description = "A simple description"

def __init__(self, **kwargs):
    super().__init__(**kwargs)

    self.realIn = 1
    self.realOut = 3.0
    self.para = 1.0
    self.booleanVariable = True
    self.stringVariable = "Hello World!"
    self.register_variable(Real("realIn", causality=Fmi2Causality.input))
    self.register_variable(Real("realOut", causality=Fmi2Causality.output))
    self.register_variable(Real("para", causality=Fmi2Causality.parameter))
    self.register_variable(Boolean("booleanVariable", causality=Fmi2Causality.local))
    self.register_variable(String("stringVariable", causality=Fmi2Causality.local))

    # Note:
    # it is also possible to explicitly define getters and setters as lambdas in case the variable is not backed by a Python field.
    # self.register_variable(Real("myReal", causality=Fmi2Causality.output, getter=lambda: self.realOut, setter=lambda v: set_real_out(v))

def do_step(self, current_time, step_size):
    self.realOut = self.realIn * self.para
    return True

`

markaren commented 7 months ago

Windows? Linux? 64-bit or 32 bit Python installed? Python available globally? Does the app have it's own Python runtime? etc.

a3678911 commented 7 months ago

windows 64-bit, and 64-bit 3.8.5 python using anaconda environment. I try to run other python codes in matlab.

a3678911 commented 7 months ago

How does pythonFMU decide which compliers to use if both MSVC and Mingw are installed in my PC? And where can specify 64-bit or 32-bit?

markaren commented 7 months ago

You mean when compiling the native library from source? That depends how you setup your toolchain. When invoking the build script, however, it should select 64-bit MSVC.

The pre-compiled binary shipped with the pip/conda packages is 64-bit MSVC.

MinsGoing commented 7 months ago

I'm having the same problem. after importing into simulink, the runtime crashed straight away

markaren commented 7 months ago

Unfortunatly, I don't have a solution. Some tools/environments are harder to pinpoint the issue for, and will require debugging expertise.

MinsGoing commented 7 months ago

Unfortunatly, I don't have a solution. Some tools/environments are harder to pinpoint the issue for, and will require debugging expertise.

Everything works fine in FMPy GUI, import to simulink without scope connected, click to run without crashing, connect to scope to run and it crashes. python is already in the environment path.

markaren commented 7 months ago

According to #110 this issue is due to Anaconda PATH not set (fixable).