Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the new python api #983

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/OMSimulatorPython/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ def terminate(self):
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))

def reset(self):
status = Scope._capi.reset(self.cref)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))

def getBoolean(self, cref):
value, status = Scope._capi.getBoolean(self.cref + '.' + cref)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))
return value

def getInteger(self, cref):
value, status = Scope._capi.getInteger(self.cref + '.' + cref)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))
return value

def getReal(self, cref):
value, status = Scope._capi.getReal(self.cref + '.' + cref)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))
return value

@property
def cref(self):
return self._cref
Expand Down Expand Up @@ -99,3 +122,10 @@ def resultFile(self, file: str):
status = Scope._capi.setResultFile(self.cref, file, bufferSize)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))

@property
def modelState(self):
modelState, status = Scope._capi.getModelState(self.cref)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))
return Types.ModelState(modelState)
9 changes: 9 additions & 0 deletions src/OMSimulatorPython/Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ class System(Enum):
TLM = 1 # TLM system
WC = 2 # Weakly Coupled system
SC = 3 # Strongly Coupled system

class ModelState(Enum):
'oms_modelState_enu_t'
VIRGIN = 1
ENTERINSTANTIATION = 2
INSTANTIATED = 4
INITIALIZATION = 8
SIMULATION = 16
ERROR = 32
6 changes: 6 additions & 0 deletions src/OMSimulatorPython/capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self):
self.obj.oms_getFixedStepSize.restype = ctypes.c_int
self.obj.oms_getInteger.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_int)]
self.obj.oms_getInteger.restype = ctypes.c_int
self.obj.oms_getModelState.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_int)]
self.obj.oms_getModelState.restype = ctypes.c_int
self.obj.oms_getReal.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_double)]
self.obj.oms_getReal.restype = ctypes.c_int
self.obj.oms_getResultFile.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(ctypes.c_int)]
Expand Down Expand Up @@ -218,6 +220,10 @@ def getInteger(self, cref):
value = ctypes.c_int()
status = self.obj.oms_getInteger(cref.encode(), ctypes.byref(value))
return [value.value, status]
def getModelState(self, cref):
value = ctypes.c_int()
status = self.obj.oms_getModelState(cref.encode(), ctypes.byref(value))
return [value.value, status]
def getReal(self, cref):
value = ctypes.c_double()
status = self.obj.oms_getReal(cref.encode(), ctypes.byref(value))
Expand Down