"output_D": model.mini.model_two.outport }) sim.setRealTimePlatformThreads() def output_on_A(evt): global on_A on_A = evt[0] def output_on_B(evt): global on_B on_B = evt[0] sim.setListenPorts(model.output_A, output_on_A) sim.setListenPorts(model.mini.output_B, output_on_B) sim.simulate() import time on_A = None on_B = None sim.realtime_interrupt("input_A 1") time.sleep(1) if not (on_A == "1" and on_B == "1"): raise Exception("Expected input on A or B output port") on_A = None on_B = None
"unknown state <%s> in TrafficLight time advance transition function"\ % state) # ====================================================================== # class TrafficLightSystem(CoupledDEVS): def __init__(self): CoupledDEVS.__init__(self, "System") self.light = self.addSubModel(TrafficLight("Light")) self.observed = self.addOutPort(name="observed") self.connectPorts(self.light.OBSERVED, self.observed) def my_function(event): print("Observed the following event: " + str(event)) from pypdevs.simulator import Simulator model = TrafficLightSystem() sim = Simulator(model) sim.setRealTime() sim.setListenPorts(model.observed, my_function) sim.simulate() import time while 1: time.sleep(0.1)