Skip to content

Commit

Permalink
Extend the new python api (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored Mar 9, 2021
1 parent 3ff6a4b commit 5396e6b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
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

0 comments on commit 5396e6b

Please sign in to comment.