Module simwbRT

Module simwbRT

The PYToolkit realtime Python API module.

An example real-time script:

    #!/usr/bin/env python
    import sys
    import os
    import simwbPath
    import simwbRT
    import simwbConstants
    
    #
    # Do your module-specific initialization here
    #
    
    simwbRT.mapRTDB()
    pgmName = os.path.basename(sys.argv[1])
    simwbRT.initLog(pgmName);
    simwbRT.initSched(sys.argv[1])
    
    try:
        while True:
            simwbRT.waitNextFrame()
            
            #
            # Do your work here
            #
            
    except KeyboardInterrupt:
        # SIGINT is sent at the end of test
        sys.exit(0)

An example initializatiion script:

    #!/usr/bin/env python
    import sys
    import os
    import simwbPath
    import simwbRT
    import simwbConstants
    
    #
    # Do your module-specific initialization here
    #
    
    simwbRT.mapRTDB()
    pgmName = os.path.basename(sys.argv[1])
    simwbRT.initLog(pgmName);
    simwbRT.initScriptSched(sys.argv[1])
    
    #
    # Do your work here
    #
    
    sys.exit(0)

Functions
 
addGenerator(...)
int = simwbRT.addGenerator(name, endCondT, signalT, freq, amp, phase, offset, duty, noise, duration)
 
appendGenerator(...)
None = simwbRT.appendGenerator(first, second)
 
getCVTValue(...)
ret = simwbRT.getCVTValue(name)
 
getCVTValueFromIndex(...)
ret = simwbRT.getCVTValueFromIndex(index)
 
getFrameCount(...)
int = simwbRT.getFrameCount()
 
getFrameLength(...)
int = simwbRT.getFrameLength()
 
getFrameRate(...)
float = simwbRT.getFrameRate()
 
getInitialConditionName(...)
string = simwbRT.getInitialConditionName()
 
getItemIndex(...)
int = simwbRT.getItemIndex(name)
 
getItemMeta(...)
dict = simwbRT.getItemMeta(name)
 
getRTDBName(...)
string = simwbRT.getRTDBName()
 
getRunTimeFlags(...)
int = simwbRT.getRunTimeFlags(name)
 
getRunTimeFlagsFromIndex(...)
int = simwbRT.getRunTimeFlagsFromIndex(index)
 
getSessionUserParm(...)
string = simwbRT.getSessionUserParm()
 
getTestSession(...)
dict = simwbRT.getTestSession()
 
initFailed(...)
None = simwbRT.initFailed()
 
initLog(...)
None = simwbRT.initLog(name)
 
initSched(...)
int = simwbRT.initSched(name)
 
initScriptSched(...)
int = simwbRT.initScriptSched(name)
 
logMessage(...)
None = simwbRT.logMessage(text [, severity])
 
mapRTDB(...)
int = simwbRT.mapRTDB()
 
modelCopyInputs(...)
Copy the output variables from other models to this model's inputs.
 
modelDataExchangeInit(...)
None = simwb_ModelDataExchangeInit(text modelName)
 
rampRate(...)
int = simwbRT.rampRate(name, duration, rate, initCond, initValue)
 
rampToValue(...)
int = simwbRT.rampToValue(name, endValue, rate, initCond, initValue)
 
setAlternateValue(...)
None = simwbRT.setAltValue(name, value)
 
setAlternateValueFlag(...)
None = simwbRT.setAlternateValueFlag(name, state)
 
setAlternateValueFlagFromIndex(...)
None = simwbRT.setAlternateValueFlagFromIndex(index, state)
 
setAlternateValueFromIndex(...)
None = simwbRT.setAltValueFromIndex(index, value)
 
setCVTValue(...)
None = simwbRT.setCVTValue(name, value)
 
setCVTValueFromIndex(...)
None = simwbRT.setCVTValueFromIndex(index, value)
 
setOperatorFlag(...)
None = simwbRT.setOperatorFlag(name, state)
 
setOperatorFlagFromIndex(...)
None = simwbRT.setOperatorFlagFromIndex(index, state)
 
startAllGenerators(...)
None = simwbRT.startAllGenerators()
 
startGenerator(...)
None = simwbRT.startGenerator(genNum)
 
stopAllGenerators(...)
None = simwbRT.stopAllGenerators()
 
stopGenerator(...)
None = simwbRT.stopGenerator(genNum)
 
testStop(...)
None = simwbRT.testStop(reason)
 
timeStamp(...)
double = simwbRT.timeStamp()
 
waitAsyncResume(...)
int = simwbRT.waitAsyncResume(int microSec)
 
waitNextFrame(...)
None = simwbRT.waitNextFrame()
 
writeStdOut(...)
None = simwbRT.writeStdOut(text)
Variables
  __package__ = None
Function Details

addGenerator(...)

 
int = simwbRT.addGenerator(name, endCondT, signalT, freq, amp, phase, offset, duty, noise, duration)

    'name' is an RTDB item name (string).
    'endCondT' is one of:
        simwbConstants.GEN_SIGGENEND_DURATION
            (terminate after the duration specified elapses).
        This is currently the only supported type. Other types will be added
        in the future.
    'signalT' is one of:
        simwbConstants.SIG_TYPE_*
            (but NOT SIG_TYPE_RAMP which is reserved, and has it's own calls)
    'freq' is frequency in Hz (float)
    'amp' is amplitude (float)
    'phase' is phase (float)
    'offset' is offset from 0 (float)
    'duty' is duty cycle in % (0-100) (float)
    'noise' is additional white noise component to add (float)
    'duration' in seconds (float)

Create a signal generator of the given type and attach it to the specified item.
Arguments that don't make sense for a given type of signal are ignored, but must
be present.

Return the generator number, or <0 on error.

appendGenerator(...)

 
None = simwbRT.appendGenerator(first, second)

    'first' is the first generator number (int).
    'second' is the second generator number (int).

Append a second generator that starts running when the first has
finished executing. These are generator numbers as returned by
simwb_addGenerator(), simwb_rampRate() or simwb_rampToValaue().

No return (None).

getCVTValue(...)

 
ret = simwbRT.getCVTValue(name)

    'name' is an RTDB item name (string).

Returns the CVT value of an RTDB item given its name. The type
of the return value will match the type of the item. Always
returns a list, or None on error.

getCVTValueFromIndex(...)

 
ret = simwbRT.getCVTValueFromIndex(index)

    'index' is an RTDB item index returned by simwb_getItemIndex().

Returns the CVT value of an RTDB item given its index. The type
of the return value will match the type of the item. Always
returns a list, or None on error.

getFrameCount(...)

 

int = simwbRT.getFrameCount()

Return the test frame count (int).

getFrameLength(...)

 

int = simwbRT.getFrameLength()

Return the test frame length in microseconds (int).

getFrameRate(...)

 

float = simwbRT.getFrameRate()

Return the test frame rate in Hz (float).

getInitialConditionName(...)

 

string = simwbRT.getInitialConditionName()

Returns the initial conditions name for this test.

getItemIndex(...)

 
int = simwbRT.getItemIndex(name)

    'name' is an RTDB item name string.

Return the RTDB item hash index. This can be used for later get/set
operations. Using the index calls is slightly faster than the
by-name calls.

Return >=0 on success, <0 on failure.

getItemMeta(...)

 
dict = simwbRT.getItemMeta(name)

    'name' is an RTDB item name (string).

Return this RTDB item meta information in a dictionary as:
    {
      'hashIndex': int,
      'A': float,
      'B': float,
      'pointtype': int,
      'rawtype': int,
      'cvttype': int,
      'numelements': int,
      'eumaxvalue': float,
      'euminvalue': float,
      'loggingperiod': int,
      'metaflags': int,
      'eumsgperiod': int,
      'description': string,
      'engunits': string
    }

getRTDBName(...)

 

string = simwbRT.getRTDBName()

Returns the name if the current RTDB.

getRunTimeFlags(...)

 
int = simwbRT.getRunTimeFlags(name)

    'name' is an RTDB item name (string).

Returns the RTDB item's current runtime flags as bits in an integer.
The user can use the following masks to extract individual flags or
bit fields:
    simwbConstants.RTDB*
    simwbConstants.METAFL_*

None returned on error.

getRunTimeFlagsFromIndex(...)

 
int = simwbRT.getRunTimeFlagsFromIndex(index)

    'index' is an RTDB item index returned by simwb_getItemIndex().

Returns the RTDB item's current runtime flags as bits in an integer.
The user can use the following masks to extract individual flags or
bit fields:
    simwbConstants.RTDB*
    simwbConstants.METAFL_*

None returned on error.

getSessionUserParm(...)

 

string = simwbRT.getSessionUserParm()

Returns a string with the session parameter specified when starting the test:

getTestSession(...)

 
dict = simwbRT.getTestSession()

Returns a dictionary with the test and session names as:
    {
      'testId': string,
      'sessionId: string
    }

initFailed(...)

 

None = simwbRT.initFailed()

Notify the scheduler that model initialization has failed and the run should be aborted.

No return (None).

initLog(...)

 
None = simwbRT.initLog(name)

    'name' is a string you give to the task.

Connect this task on the SimWB logger.

The 'name' will be used when displaying messages to the user.

No return (None).

initSched(...)

 
int = simwbRT.initSched(name)

    'name' is a string you give to the task.

Initialize this task on the SimWB scheduler.

Before returning this call will tell the scheduler that this
task has completed initialization and is ready to run.

Return 0 on success, <0 on failure.

initScriptSched(...)

 
int = simwbRT.initScriptSched(name)

    'name' is a string you give to the task.

Initialize this initialization script task on the SimWB scheduler.

Initialization scripts must exit before the test will start running.

Return 0 on success, <0 on failure.

logMessage(...)

 
None = simwbRT.logMessage(text [, severity])

    'text' is the message to display.
    'severity' is the message severity level (optional). One of:
        simwbConstants.LOG_INFO (default)
        simwbConstants.LOG_WARNING
        simwbConstants.LOG_ERROR
        simwbConstants.LOG_CRITICAL
            Critical errors should result in a test stop (performed
            by this task via simwb_testStop()).

Send a message to the operator.

No return (None).

mapRTDB(...)

 

int = simwbRT.mapRTDB()

Map the RTDB active RTDB into the task.

This needs to be done in order to access the actual shared memory of the running test. Otherwise a local copy is used.

Return 0 on success, <0 on failure.

modelCopyInputs(...)

 
Copy the output variables from other models to this model's inputs. 
   This call should be placed in the simulation loop after the ccurSched_waitNextFrame() call.
   This call will perform unit conversion between the output items from other models and inputs into this model.
   If model exchange has not been configured for this model, nothing happens and this call returns immediately.

No return (None).

modelDataExchangeInit(...)

 
None = simwb_ModelDataExchangeInit(text modelName)

    Initialize the data structure necessary to support model data exchange. 
     param modelName String with the user model name. Usually argv[1] from the command line.
Return int code from the routineOK if >= 0

rampRate(...)

 
int = simwbRT.rampRate(name, duration, rate, initCond, initValue)

    'name' is an RTDB item name (string).
    'duration' in seconds (float).
    'rate' is the rate in units/sec to ramp up/down (float).
    'initCond' is the initial condition type, one of:
        simwbConstants.GEN_SIGGENINIT_USER (use 'initValue' as the ramp start)
        simwbConstants.GEN_SIGGENINIT_DB (use the current RTDB value as the ramp start)
    'initValue' is the item initial value when 'initCond' is
       simwbConstants.GEN_SIGGENINIT_USER (float).

Create a signal generator that ramps the item value up/down for a specified
duration.

Return the generator number, or <0 on error.

rampToValue(...)

 
int = simwbRT.rampToValue(name, endValue, rate, initCond, initValue)

    'name' is an RTDB item name (string).
    'endValue' is the terminal or target ramp value (float).
    'rate' is the rate in units/sec to ramp up/down.
    'initCond' is the initial condition type, one of:
        simwbConstants.GEN_SIGGENINIT_USER (use 'initValue' as the ramp start)
        simwbConstants.GEN_SIGGENINIT_DB (use the current RTDB value as the ramp start)
    'initValue' is the item initial value when 'initCond' is simwbConstants.GEN_SIGGENINIT_USER.

Create a signal generator that ramps the item value up/down to a specified
value.

Return the generator number, or <0 on error.

setAlternateValue(...)

 
None = simwbRT.setAltValue(name, value)

    'name' is an RTDB item name (string).
    'value' is a scalar Python double.

Set the RTDB item alternate (Alt) value.

No return (None).

setAlternateValueFlag(...)

 
None = simwbRT.setAlternateValueFlag(name, state)

    'name' is an RTDB item name (string).
    'state' is an int, 0=clear, nonzero=set.

Set the RTDB items run time alternate value flag to the given state.

No return (None).

setAlternateValueFlagFromIndex(...)

 
None = simwbRT.setAlternateValueFlagFromIndex(index, state)

    'index' is an RTDB item index returned by simwb_getItemIndex().
    'state' is an int, 0=clear, nonzero=set.

Set the RTDB items run time alternate value flag to the given state.

No return (None).

setAlternateValueFromIndex(...)

 
None = simwbRT.setAltValueFromIndex(index, value)

    'index' is an RTDB item index returned by simwb_getItemIndex().
    'value' is a scalar Python double.

Set the RTDB item alternate (Alt) value.

No return (None).

setCVTValue(...)

 
None = simwbRT.setCVTValue(name, value)

    'name' is an RTDB item name (string).
    'value' is a Python list of values.
        Scalars should be passed as a list with only one value.

Set the RTDB item current (CVT) value.

No return (None).

setCVTValueFromIndex(...)

 
None = simwbRT.setCVTValueFromIndex(index, value)

    'index' is an RTDB item index returned by simwb_getItemIndex().
    'value' is a Python list of values.
        Scalars should be passed as a list with only one value.

Set the RTDB item current (CVT) value.

No return (None).

setOperatorFlag(...)

 
None = simwbRT.setOperatorFlag(name, state)

    'name' is an RTDB item name (string).
    'state' is an int, 0=clear, nonzero=set.

Set the RTDB items run time operator flag to the given state.

No return (None).

setOperatorFlagFromIndex(...)

 
None = simwbRT.setOperatorFlagFromIndex(index, state)

    'index' is an RTDB item index returned by simwb_getItemIndex().
    'state' is an int, 0=clear, nonzero=set.

Set the RTDB items run time operator flag to the given state.

No return (None).

startAllGenerators(...)

 

None = simwbRT.startAllGenerators()

Starts all the loaded signal generators.

No return (None).

startGenerator(...)

 
None = simwbRT.startGenerator(genNum)

    'genNum' is the generator number returned by simwb_addGenerator(),
             simwb_rampRate() or simwb_rampToValue().

Starts the specified signal generator.

No return (None).

stopAllGenerators(...)

 

None = simwbRT.stopAllGenerators()

Stops all the loaded signal generators.

No return (None).

stopGenerator(...)

 
None = simwbRT.stopGenerator(genNum)

    'genNum' is the generator number returned by simwb_addGenerator(),
             simwb_rampRate() or simwb_rampToValue().

Stops the specified signal generator.

No return (None).

testStop(...)

 
None = simwbRT.testStop(reason)

    'reason' is one of:
        simwbConstants.SCHED_*

Stop the test for the specified reason.

No return (None).

timeStamp(...)

 

double = simwbRT.timeStamp()

Return the current time in seconds since the epoch.

Return double number of seconds.

waitAsyncResume(...)

 
int = simwbRT.waitAsyncResume(int microSec)

  Block the calling task until resumed.
  param microSec : controls the behavior of the wait/resume mechanism.
  The task resume mechanism depends on the value of microSec passed into the call and on its position in the execution chain .
  When the task is NOT first in the execution, it is resumed bu its predecessor in the execution chain once the predecessor has completed execution.
  When the task is first in the execution chain :
  microSec > 0 : the routine will do a usleep(microSec)
  microSec ==-1 : the routine will do a pause() and will be resumed by a any signal ; typically a timer. See the asynchronous model template for an example.
  microSec == 0,: the routine will resurn immediately.

Return int with call result

waitNextFrame(...)

 

None = simwbRT.waitNextFrame()

Wait here until the scheduler releases this task to run.

No return (None).

writeStdOut(...)

 
None = simwbRT.writeStdOut(text)

    'text' is the message to write (string).

Send the text message to the script stdout stream.

No return (None).