def accessSignal(
):  ######Might not be needed. setSignal accesses signal control
    """Access subsystem by subsystem Id (one value at a time for now)"""
    acquire.connectToModel()
    subSystemList = OpalApiPy.GetSubsystemList()

    # Displays available subSystems along with their ID and value.
    subSystemSignals = OpalApiPy.GetControlSignalsDescription()
    systemList = [subSystemSignals]

    print("****************Available Signals******************")
    for systems in systemList:
        systemInfo = systems
        for signal in systemInfo:

            signalType, subSystemId, path, signalName, reserved, readonly, value = signal
            print("SubSystem Name:{}  SubSystemID:{}  SignalName:{}  Value:{}".
                  format(path, subSystemId, signalName, value))

    chooseId = (int(raw_input("Choose subsystem Id to be accessed: ")))
    OpalApiPy.GetSignalControl(chooseId, 1)

    print "Subsystem %s control accessed." % chooseId
    signalType, subSystemId, path, label, reserved, readonly, value = subSystemSignals[
        chooseId - 1]
    print(
        "Subsystem Name:{}  Signal Name:{} SignalID:{}  ReadOnly:{} Value:{}".
        format(path, label, chooseId, readonly, value))
Beispiel #2
0
def getSyncClockPath(
        project,
        model):  #ADDED To acquisition thread class CAN POSSIBLY REMOVE
    """Returns model clock path for asynchronous acquisition"""

    acquire.connectToModel(project, model)
    projectPath, modelName = OpalApiPy.GetCurrentModel()
    modelName = os.path.splitext(modelName)
    clockpath = modelName[0] + '/sm_master/clock/port1'
    simulationTime = OpalApiPy.GetSignalsByName(clockpath)
    return simulationTime
def acquisitionSignalsParse(project, model):
    """Parses acquisition signals from main signal description list. Designed for use with setting
    IdxVgs and Varheader in ePhasorsim acquisition port selection"""
    acquire.connectToModel(project, model)
    allSignals = list(OpalApiPy.GetSignalsDescription())
    ephasor_port_out = []
    for signal in allSignals:
        if signal[0] == 0:
            ephasor_port_out.append(signal[3])
    OpalApiPy.Disconnect()
    return ephasor_port_out
Beispiel #4
0
    def run(self):
        print "Thread- " + self.threadName
        self.lock.acquire()
        try:
            acquire.connectToModel(self.project, self.model)
            modelState, realTimeFactor = OpalApiPy.GetModelState()
            self.lock.release()
        except:
            print 'Could not connect thread ' + self.threadName
        else:
            while (modelState == OpalApiPy.MODEL_RUNNING
                   and self.kill.is_set() is False
                   ):  #or modelState == OpalApiPy.MODEL_PAUSED):
                if modelState == OpalApiPy.MODEL_PAUSED and self.acq_wait.is_set(
                ) is False:
                    #self.acq_wait.clear()
                    #OpalApiPy.Disconnect()
                    logging.warning('Thread Acq {} Paused '.format(
                        self.threadName))
                    self.acq_wait.wait(1)
                    self.acq_wait.set()
                    logging.warning('Thread Acq {} Resumed '.format(
                        self.threadName))
                else:
                    try:
                        self.lock.acquire()
                        acqList = OpalApiPy.GetAcqGroupSyncSignals(
                            self.GroupNumber - 1, 0, 0, 1, 1)
                        self.lock.release()
                    except:
                        logging.warning('<Acquisition Not Available>')
                        break

                sigVals, monitorInfo, simTimeStep, endFrame = acqList
                missedData, offset, self.simulationTime, self.sampleSec = monitorInfo
                if (self.interval <= self.simulationTime - self.lastAcqTime):
                    if (self.sample_time_error <=
                            self.simulationTime - self.lastAcqTime):
                        logging.warning(
                            '<Acquisition sample step missed at {}>'.format(
                                self.simulationTime))
                        self.lastAcqTime = self.simulationTime
                    else:
                        # self.lock.acquire()
                        self.condition.acquire()
                        self.dataList.dataValues.append(tuple(sigVals))
                        self.condition.notifyAll()
                        self.condition.release()
                        # self.lock.release()
                        self.lastAcqTime = self.simulationTime
                modelState, realTimeFactor = OpalApiPy.GetModelState()
        self.kill.set()
        #OpalApiPy.Disconnect()
        print "Thread- " + self.threadName + " Exited"
def accessAllSignals(
):  ######Might not be needed since set signal overrides signalControl
    """"Gives user access to models's control signals. One client API granted signal control at a time"""

    subsystemId = 0  # 0 takes control of all subsystems
    signalControl = 0  # requests signal control when value == 1

    # Connect to model if connection is not already made
    acquire.connectToModel()
    modelState, realTimeMode = OpalApiPy.GetModelState()

    try:
        if (modelState == OpalApiPy.MODEL_RUNNING):
            # Access signal control
            signalControl = 1
            OpalApiPy.GetSignalControl(subsystemId, signalControl)
            print "Signal control accessed"
        else:
            print "Model state not ready for signal access"
    finally:
        print "Release signal control after changing values"
Beispiel #6
0
    def run(self):
        print "Thread- " + self.threadName
        self.lock.acquire()
        try:
            acquire.connectToModel(self.project, self.model)
            modelState, realTimeFactor = OpalApiPy.GetModelState()
            self.lock.release()
        except:
            print 'Could not connect thread ' + self.threadName
        else:
            lastIndex = 1
            # while(modelState == OpalApiPy.MODEL_RUNNING):#or modelState == OpalApiPy.MODEL_PAUSED):
            while self.kill.is_set() is False:
                lastEntry = len(self.dataList.dataValues)
                # if((lastEntry != lastIndex) & (len(self.dataList.dataValues) != 0)):
                if modelState == OpalApiPy.MODEL_PAUSED and self.acq_wait.is_set(
                ) is False:
                    # self.acq_wait.clear()
                    logging.warning('Thread Acq {} Paused '.format(
                        self.threadName))
                    self.acq_wait.wait(1)
                    self.acq_wait.set()
                    logging.warning('Thread Acq {} Resumed '.format(
                        self.threadName))
                    # break
                if lastEntry != 0:
                    # self.lock.acquire()
                    self.condition.acquire()
                    self.lastAcq = self.dataList.dataValues[lastIndex - 1]
                    self.new_data = True
                    self.condition.wait()
                    self.condition.release()
                    lastIndex = lastEntry
                    # self.lock.release()

                # modelState, realTimeFactor = OpalApiPy.GetModelState()

        #OpalApiPy.Disconnect()
        print "Thread- " + self.threadName + " Exited"
Beispiel #7
0
    def run(self):
        #Each thread must connect itself to the model through the acquire module
        acquire.connectToModel(self.project, self.model)
        self.projectPath, self.modelName = OpalApiPy.GetCurrentModel()
        modelName = os.path.splitext(self.modelName)

        #This is the default clock path as long as the user adds a clock to the sm_master for
        #time keeping if asynchronous data acquisition is needed.
        clockpath = modelName[0] + '/sm_master/clock/port1'
        modelState, realTimeFactor = OpalApiPy.GetModelState()
        while (modelState == OpalApiPy.MODEL_RUNNING):
            # Thread continues to get time until model is paused or stoped
            #Blocks GetSignalsByName process from other threads until time thread is done
            self.lock.acquire()
            self.simulationClock = OpalApiPy.GetSignalsByName(clockpath)
            # print"Simulation Time is %s" % self.simulationClock
            self.lock.release()
            modelState, realTimeFactor = OpalApiPy.GetModelState()
            sleep(self.interval)

        #Each thread must also disconnect from the API after its work has finished.
        OpalApiPy.Disconnect()
        print "Thread- " + self.threadName + " Exited"
Beispiel #8
0
    def run(self):
        print "Thread- " + self.threadName
        acquire.connectToModel(self.project, self.model)
        modelState, realTimeFactor = OpalApiPy.GetModelState()
        clockTime = simulationTimeThread(self.project, self.model,
                                         self.interval)
        # clockTime.setDaemon(True)
        clockTime.start()
        clockTime.join(1)
        simulationClock = clockTime.simulationClock
        previousAcqClock = 0
        while (modelState == OpalApiPy.MODEL_RUNNING):
            if (self.interval < (simulationClock - previousAcqClock)):
                #print"simclock %s" % simulationClock
                #print"prev acq clock %s" % previousAcqClock
                self.lock.acquire()
                #print"Lock acquired by %s" %self.threadName
                acqList = OpalApiPy.GetAcqGroupSyncSignals(
                    self.GroupNumber - 1, 0, 0, 1, self.interval)
                sigVals, monitorInfo, simTimeStep, endFrame = acqList
                # dataList = DataList(self.GroupNumber)
                self.dataList.dataValues.append(tuple(sigVals))
                #print"Lock Released by %s" %self.threadName
                self.lock.release()
                modelState, realTimeFactor = OpalApiPy.GetModelState()
                previousAcqClock = simulationClock
                #print"Thread Sleeping"
                #sleep(self.interval)
                #print"Thread UP"

            else:
                modelState, realTimeFactor = OpalApiPy.GetModelState()
                simulationClock = clockTime.simulationClock

        #OpalApiPy.Disconnect()
        print "Thread- " + self.threadName + " Exited"
Beispiel #9
0
def syncAcqReturnInfo(
        GroupNumber, interval
):  ## Useful tool for wholistic information for acquisition group
    """Performs data acquisition at the specified time interval if the model is
    running, until the model stops running"""
    #Data Acquisition parameters
    acqGroup = GroupNumber - 1
    synchronization = 0
    interpolation = 0
    threshold = 1
    acqTimeStep = 0.001

    dataRequestTime = 0
    acqControl = 1
    acquire.connectToModel('ephasorex2', 'phasor01_IEEE39')
    projectPath, modelName = OpalApiPy.GetCurrentModel()
    modelName = os.path.splitext(modelName)
    clockpath = modelName[0] + '/sm_master/clock/port1'
    simulationClock = OpalApiPy.GetSignalsByName(clockpath)
    previousAcqClock = 0
    print(simulationClock)
    # try:
    modelState, realTimeMode = OpalApiPy.GetModelState()
    print "model state %s" % modelState
    OpalApiPy.GetAcquisitionControl(acqControl, GroupNumber)

    numTriggers = 0
    while (modelState == OpalApiPy.MODEL_RUNNING):
        simulationClock = OpalApiPy.GetSignalsByName(clockpath)
        if (interval < (simulationClock - previousAcqClock)):

            print "simclock %s" % simulationClock
            print "prev acq clock %s" % previousAcqClock
            previousAcqClock = simulationClock

            acqList = OpalApiPy.GetAcqGroupSyncSignals(acqGroup, synchronization, interpolation, \
                                                                             threshold, acqTimeStep)

            sigVals, monitorInfo, simTimeStep, endFrame = acqList
            missedData, offset, simTime, sampleSec = monitorInfo

            # sets async data acquisiion to group #,rearm trigger after S seconds
            for items in monitorInfo:
                print("missed Data:{}  offset:{}  simTime:{}  sampleSec:{}".
                      format(missedData, offset, simTime, sampleSec))
            portID = 1
            for item in sigVals:
                print("ID:{}  Value:{} ".format(portID, item))
                # sampleTimeInterval = OpalApiPy.GetAcqSampleTime(1)
                # print("Sample acq interval", sampleTimeInterval)
                portID += 1

            numTriggers += 1
            print "Acquisition triggered %s times" % numTriggers
            modelState, realTimeMode = OpalApiPy.GetModelState()

        else:
            print "Interval Range not exceeded"
            modelState, realTimeMode = OpalApiPy.GetModelState()
            # previousAcqClock = simulationClock

    if (modelState != OpalApiPy.MODEL_RUNNING):
        print "Model must be running to trigger data acquisition"
        OpalApiPy.GetAcquisitionControl(acqControl, GroupNumber)
        print "Group acquisition control released"

    OpalApiPy.Disconnect()