class TamagotchipService(rpyc.Service): """ Represents the Tamagotchip game. The available methods correspond to functions of the game. Note that it uses by default the EasyDAQ USB24mx driver (this is hardcoded), and only uses the first twelve channels, as only twelve electronic valves are used on the hardware setup. """ def on_connect(self): self.c = Controller() # use driver's defaults for config self.c.set_all_output() def on_disconnect(self): self.c.disconnect() def exposed_set_states(self, states): """ Set the states of the 12 available valves :param states: A 12 item-long list of integers, representing the state of each valve. Open is 1, closed is 0. :type states: list :raises TypeError: if `states` cannot be cast to a list. :raises ValueError: if length of `states` is inappropriate. """ states = list(states) if len(states) != 12: raise ValueError("'states' must be a 12 item-long list") try: self.c.set_states(states + [0] * 12) # close the last 12 valves except Exception, e: raise e # TODO not too sure what I'm catching yet. else:
def on_connect(self): self.c = Controller() # use driver's defaults for config self.c.set_all_output()