Commit 04f22346 authored by Antonia Beteva's avatar Antonia Beteva
Browse files

Removed attr_mode. Changed _wait and _wait_mode to use gevent.

Fixed bug in _wait_mode.
Renamed _manual to _automatic to be consistent with the device server.
Changed command_inout and read_attribute to the new style PyTango command
execution and attribute reading.
Added _frontenfd to distinguish between a front end and safety shutter.
Some documentation.
parent 6b0e0e69
Pipeline #3014 passed with stages
in 13 minutes and 22 seconds
......@@ -5,24 +5,44 @@
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from gevent import Timeout, sleep
from bliss.common.tango import DeviceProxy, DevFailed
import time
"""
Tango shutter is used to control both front end and safetry shutter.
Some commands/attributes (like atomatic/manual) are only implemented in the
front end device server, set by the _frontend variable.
example yml file:
-
#front end shutter
class: tango_shutter
name: frontend
uri: //orion:10000/fe/id/30
-
#safety shutter
class:tango_shutter
name: safshut
uri: id30/bsh/1
"""
class tango_shutter:
def __init__(self, name, config):
tango_uri = config.get("uri")
tango_uri = config.get('uri')
self.name = name
self.__control = DeviceProxy(tango_uri)
try:
self._manual = config.get("attr_mode")
except:
self._manual = False
self._frontend = 'FrontEnd' in self.__control.info().dev_class
self._mode = False
def get_status(self):
print self.__control._status()
print self.__control.status()
def get_state(self):
return str(self.__control._state())
return str(self.__control.state())
def open(self):
state = self.get_state()
......@@ -30,7 +50,7 @@ class tango_shutter:
raise RuntimeError('Cannot open shutter in STANDBY state')
if state == 'CLOSE':
try:
self.__control.command_inout("Open")
self.__control.open()
self._wait('OPEN', 5)
except:
raise RuntimeError("Cannot open shutter")
......@@ -41,50 +61,65 @@ class tango_shutter:
state = self.get_state()
if state == 'OPEN' or state == 'RUNNING':
try:
self.__control.command_inout("Close")
self.__control.close()
self._wait('CLOSE', 5)
except:
raise RuntimeError("Cannot close shutter")
else:
print self.__control._status()
self.get_status()
def automatic(self):
if self._manual:
if not self._frontend:
raise NotImplementedError("Not a Front End shutter")
# try to set to automatic if manual mode only.
if self._mode == 'MANUAL':
state = self.get_state()
if state == 'CLOSE' or state == 'OPEN':
try:
self.__control.command_inout("Automatic")
self._wait_mode()
self.__control.automatic()
self._wait_mode(mode='AUTOMATIC')
except:
raise RuntimeError("Cannot open shutter in automatic mode")
raise RuntimeError("Cannot set automatic mode closing")
else:
print self.__control._status()
self.get_status()
def manual(self):
if self._manual:
if not self._frontend:
raise NotImplementedError("Not a Front End shutter")
# try to set to manual if automatic mode only.
if self._mode == 'AUTOMATIC':
state = self.get_state()
if state == 'CLOSE' or state == 'RUNNING':
try:
self.__control.command_inout("Manual")
self._wait_mode()
self.__control.manual()
self._wait_mode(mode='MANUAL')
except:
raise RuntimeError("Cannot set shutter in manual mode")
raise RuntimeError("Cannot set manual mode closing")
else:
print self.__control._status()
self.get_status()
def get_closing_mode(self):
if not self._frontend:
raise NotImplementedError("Not a Front End shutter")
try:
_mode = self.__control.automatic_mode
except Exception:
_mode = None
self._mode = 'AUTOMATIC' if _mode else \
'MANUAL' if _mode == False else 'UNKNOWN'
return self._mode
def _wait(self, state, timeout=3):
tt = time.time()
stat = self.get_state()
while stat != state or time.time() - tt < timeout:
time.sleep(1)
stat = self.get_state()
def _wait_mode(self, timeout=3):
tt = time.time()
stat = self.__control.read_attribute(self._manual).value
while stat is False or time.time() - tt < timeout:
time.sleep(1)
stat = self.__control.read_attribute(self._manual).value
with Timeout(timeout):
while self.get_state() != state:
sleep(1)
def _wait_mode(self, mode, timeout=3):
with Timeout(timeout):
while self.get_closing_mode() != mode:
sleep(1)
def __repr__(self):
try:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment