class Tango(object): """Interact with Tango system. Attributes: _db: instance of Tango database. door: instance of Sardana door. debug: debug-level log stream of Sardana. output: output-level log stream of Sardana. device_classes (list of str): supported device classes. devices (str): all devices found under classes |device_classes|. """ def __init__(self): self._db = PyTango.Database() door_name = self.find_door() if not door_name: tkMessageBox.showerror("Error", "No Sardana door found.") sys.exit(1) print door_name door_full_name = "%s:%s/%s" % \ (self._db.get_db_host(), self._db.get_db_port(), door_name) # Sardana door. self.door = BaseDoor(door_full_name) # Debug, Output stream of door log. self.debug = self.door.getLogObj('debug') self.output = self.door.getLogObj('output') self.device_classes = ["Motor", "LimaCCDs"] self.devices = [] for class_type in self.device_classes: self.devices.extend( self._db.get_device_exported_for_class( class_type).value_string) def get_device_alias(self, device): """Return the alias of |device|.""" return self._db.get_alias_from_device(device) def get_device_class(self, device): """Return the tango class of |device|.""" return self._db.get_class_for_device(device) def is_sardana_running(self): """Return True if sardana is at state ON instead of RUNNING, OFF.""" return self.door.getState() == PyTango.DevState.RUNNING def find_door(self): """Return door name. Return None if not found. Find door under server pattern MacroServer*. """ server_list = self._db.get_server_list('MacroServer/*').value_string for server in server_list: server_devs = self._db.get_device_class_list(server).value_string devs, classes = server_devs[0::2], server_devs[1::2] for idx, class_ in enumerate(classes): if class_.lower() == "door": return devs[idx] return None def run_macro(self, command): """Run macro on Sardana. Args: command (list of str): macro encapsulated in list, eg. ["wa"]. """ self.output.clearLogBuffer() self.debug.clearLogBuffer() self.door.runmacro(command) # Wait for attribute change finish. while not self.debug.getLogBuffer(): time.sleep(0.05) while self.is_sardana_running(): time.sleep(0.05)
else: return False return False DOOR_NAME = "cfeld/door/cfeld-pcx27083.01" if not is_door(DOOR_NAME): print "not door" sys.exit(1) db = PyTango.Database() door_full_name = "%s:%s/%s" % (db.get_db_host(), db.get_db_port(), DOOR_NAME) door = BaseDoor(door_full_name) output = door.getLogObj('output') debug = door.getLogObj('debug') output.clearLogBuffer() debug.clearLogBuffer() # door.runmacro(["wa"]) # door.runmacro(["mv", "exp_dmy01", "0"]) door.runmacro(["mv", "motor/dummy_mot_ctrl/1", "0"]) # door.runmacro(["ascan", "exp_dmy01", "0", "1", "10", "0.2"]) # door.runmacro(["ascan", "motor/dummy_mot_ctrl/1", "0", "1", "10", "0.2"]) while not debug.getLogBuffer(): print "empty" time.sleep(0.05) while door.getState() == PyTango.DevState.RUNNING: print "running" time.sleep(0.05) print output.getLogBuffer() print debug.getLogBuffer()