From 700e1dd0d66111bb2f0f164be5772ad1c6b5d2e1 Mon Sep 17 00:00:00 2001 From: TT Date: Wed, 11 Dec 2024 10:36:34 +0100 Subject: [PATCH] fixing windows handle issue --- examples/FMI2/BouncingBall/src/BouncingBall.jl | 3 +-- src/FMI2_simple.jl | 12 ++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/FMI2/BouncingBall/src/BouncingBall.jl b/examples/FMI2/BouncingBall/src/BouncingBall.jl index 2b79dbb..1ff08e2 100644 --- a/examples/FMI2/BouncingBall/src/BouncingBall.jl +++ b/examples/FMI2/BouncingBall/src/BouncingBall.jl @@ -55,7 +55,6 @@ FMU_FCT_EVALUATE = function(t, x_c, ẋ_c, x_d, u, p, eventMode) v = 0.0 end end - end a = (m * -g) / m # the system's physical equation (a little longer than necessary) @@ -147,7 +146,7 @@ end ### FMIBUILD_NO_EXPORT_BEGIN ### # The line above is a start-marker for excluded code for the FMU compilation process! -tmpDir = mktempdir(; prefix="fmibuildjl_test_", cleanup=false) +tmpDir = "C:\\Users\\thummeto\\Documents\\FMIExport.jl\\tmp" # mktempdir(; prefix="fmibuildjl_test_", cleanup=false) @info "Saving example files at: $(tmpDir)" fmu_save_path = joinpath(tmpDir, "BouncingBall.fmu") diff --git a/src/FMI2_simple.jl b/src/FMI2_simple.jl index fb6ebd3..3337d52 100644 --- a/src/FMI2_simple.jl +++ b/src/FMI2_simple.jl @@ -55,7 +55,7 @@ function evaluate(_component::fmi2Component, eventMode=false) tmp_xc, ẋc, tmp_xd, p = FMU_FCT_EVALUATE(component.t, xc, ẋc, xd, u, p, eventMode) if eventMode # overwrite state vector allowed - component.eventInfo.valuesOfContinuousStatesChanged = (xc != tmp_xc ? fmi2True : fmi2False) + component.eventInfo.valuesOfContinuousStatesChanged = (xc != tmp_xc ? fmi2True : component.eventInfo.valuesOfContinuousStatesChanged) #component.eventInfo.newDiscreteStatesNeeded = (xd != tmp_xd ? fmi2True : fmi2False) xc = tmp_xc @@ -406,6 +406,7 @@ function simple_fmi2SetContinuousStates(_component::fmi2Component, _x::Ptr{fmi2R if nx != length(component.fmu.modelDescription.stateValueReferences) logWarning(component, "fmi2SetContinuousStates: Model has $(length(component.fmu.modelDescription.stateValueReferences)) states, but `nx`=$(nx).") + return fmi2StatusWarning end x = unsafe_wrap(Array{fmi2Real}, _x, nx) @@ -432,7 +433,7 @@ function simple_fmi2NewDiscreteStates(_component::fmi2Component, _fmi2eventInfo: component = dereferenceInstance(_component) if component.state != fmi2ComponentStateEventMode - logError(component, "fmi2NewDiscreteStates must be called in event mode, mode is `$(component.state )`!") + logError(component, "fmi2NewDiscreteStates must be called in event mode, mode is `$(component.state)`!") return fmi2StatusError end @@ -447,6 +448,9 @@ function simple_fmi2NewDiscreteStates(_component::fmi2Component, _fmi2eventInfo: eventInfo.nextEventTimeDefined = fmi2False # [ToDo] eventInfo.nextEventTime = 0.0 # [ToDo] unsafe_store!(_fmi2eventInfo, eventInfo); + + # reset + eventInfo.valuesOfContinuousStatesChanged = fmi2False return fmi2StatusOK end @@ -476,6 +480,7 @@ function simple_fmi2GetDerivatives(_component::fmi2Component, _derivatives::Ptr{ if nx != length(component.fmu.modelDescription.derivativeValueReferences) logWarning(component, "fmi2GetDerivatives: Model has $(length(component.fmu.modelDescription.derivativeValueReferences)) states, but `nx`=$(nx).") + return fmi2StatusWarning end derivatives = unsafe_wrap(Array{fmi2Real}, _derivatives, nx) @@ -493,6 +498,7 @@ function simple_fmi2GetEventIndicators(_component::fmi2Component, _eventIndicato if ni != length(component.fmu.modelDescription.numberOfEventIndicators) logWarning(component, "fmi2GetEventIndicators: Model has $(length(component.eventIndicators)) states, but `ni`=$(ni).") + return fmi2StatusWarning end eventIndicators = unsafe_wrap(Array{fmi2Real}, _eventIndicators, ni) @@ -513,6 +519,7 @@ function simple_fmi2GetContinuousStates(_component::fmi2Component, _x::Ptr{fmi2R if nx != length(component.fmu.modelDescription.stateValueReferences) logWarning(component, "fmi2GetContinuousStates: Model has $(length(component.fmu.modelDescription.stateValueReferences)) states, but `nx`=$(nx).") + return fmi2StatusWarning end x = unsafe_wrap(Array{fmi2Real}, _x, nx) @@ -530,6 +537,7 @@ function simple_fmi2GetNominalsOfContinuousStates(_component::fmi2Component, _x_ if nx != length(component.fmu.modelDescription.stateValueReferences) logWarning(component, "fmi2GetNominalsOfContinuousStates: Model has $(length(component.fmu.modelDescription.stateValueReferences)) states, but `nx`=$(nx).") + return fmi2StatusWarning end x_nominal = unsafe_wrap(Array{fmi2Real}, _x_nominal, nx)