def errorHandler(self): """ Implementation errorHandler method for errorHandler() """ printf("Logging error from state: %s and recover in 3 seconds.", self.__state) self.__error_flag = False time.sleep(3.0) # Recover from error and re-execute sim_state_start.sendEvent("Recover")
def Action(self, act): """ Generic state action code. """ self.__state = self.getCurrentState() if self.__error_flag == True: print "%s.%s() ERROR in state %s" % (self.__machine_name, act, self.__state) sim_state_start.sendEvent("Error") return print "%s.%s() default action implementation invoked in state %s" % (self.__machine_name, act, self.__state)
def Action(self, act): """ Generic state action code. """ self.__state = self.getCurrentState() if self.__error_flag == True: print "%s.%s() ERROR in state %s" % (self.__machine_name, act, self.__state) sim_state_start.sendEvent("Error") return print "%s.%s() default action implementation invoked in state %s" % ( self.__machine_name, act, self.__state)
print "Timeout: looking for expected current state: %s" % current_state sys.exit(-1) return current_state if __name__ == "__main__": # # Start all Statecharts in ./autocode without trace gui widget # sim_state_start.main() time.sleep(5) # # send event PwrOn to Simple1 # print "Send PwrOn event." sim_state_start.sendEvent('PwrOn') # # wait for current state to enter Idle # current_state = checkState("Simple1", "Idle") print "Current state is: %s\n" % current_state # # send event PwrOff to Simple1 # print "Send PwrOff event." # # wait for current state to enter Off # sim_state_start.sendEvent('PwrOff') current_state = checkState("Simple1", "Off") print "Current state is: %s\n" % current_state
print "Timeout: looking for expected current state: %s" % current_state sys.exit(-1) return current_state if __name__ == "__main__": # # Start all Statecharts in ./autocode without trace gui widget # sim_state_start.main() time.sleep(5) # # send event PwrOn to Simple1 # print "Send PwrOn event." sim_state_start.sendEvent('PwrOn') # # wait for current state to enter Idle # current_state = checkState("Simple1","Idle") print "Current state is: %s\n" % current_state # # send event PwrOff to Simple1 # print "Send PwrOff event." # # wait for current state to enter Off # sim_state_start.sendEvent('PwrOff') current_state = checkState("Simple1","Off") print "Current state is: %s\n" % current_state