示例#1
0
app.config['SECRET_KEY'] = "nosecretfornow"
app.register_error_handler(Exception, exception_handler)

sess = Session()
sess.init_app(app)

socketio = SocketIO(manage_session=False)
socketio.init_app(app)

# the following test prevents Flask from initializing twice
# (because of the Reloader)
if not app.debug or os.environ.get("WERKZEUG_RUN_MAIN") == "true":
    hwr_directory = cmdline_options.hwr_directory
    hwr.addHardwareObjectsDirs(
        [os.path.join(os.path.dirname(__file__), 'HardwareObjects')])
    hwr = hwr.HardwareRepository(
        os.path.abspath(os.path.expanduser(hwr_directory)))
    hwr.connect()

    init_logging()

    from routes import loginutils

    # Make the valid_login_only decorator available on app object
    app.restrict = loginutils.valid_login_only

    # Importing all REST-routes
    from routes import (Main, Login, Beamline, Mockups, Utils, SampleCentring,
                        SampleChanger, Diffractometer, Queue, lims, qutils,
                        workflow, Detector, ra)

    # Install server-side UI state storage
示例#2
0
    def setMnemonic(self, mne):
        self.getProperty('mnemonic').setValue(mne)

        proc = HardwareRepository.HardwareRepository().getProcedure(mne)

        self.__setProcedure(proc)
示例#3
0
        self.setProperty("centring_phi_increment", value)

    def getCentringSampleType(self):
        return self.centring_sample_type

    def setCentringSampleType(self, value):
        self.centring_sample_type = value
        self.setProperty("centring_sample_type", value)

    def save(self):
        self.commitChanges()


if __name__ == '__main__':
    hwr_directory = os.environ["XML_FILES_PATH"]
    hwr = HardwareRepository.HardwareRepository(os.path.abspath(hwr_directory))
    hwr.connect()

    env = hwr.getHardwareObject("/px1configuration")

    print "PX1 Configuration "
    use_edna = env.getUseEDNA()
    print "    use_edna %s / (type: %s)" % (use_edna, type(use_edna))
    print "    pin_length", env.getPinLength()
    print "    centring"
    print "       nb points", env.getCentringPoints()
    print "       phi incr", env.getCentringPhiIncrement()
    print "       sample type", env.getCentringSampleType()
    env.setUseEDNA("False")
    env.setPinLength("10")
    print "    use_edna %s " % env.getUseEDNA()
示例#4
0
    def __init__(self, parent = None, widgetName = ''):       
        Connectable.Connectable.__init__(self)
        QWidget.__init__(self, parent, widgetName)

        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
        self.propertyBag = PropertyBag.PropertyBag()
                
        self.__enabledState = True #saved enabled state
        self.__loadedHardwareObjects = []
        self._signalSlotFilters = {}
        self._widgetEvents = []
 
        #
        # add what's this help
        #
        QWhatsThis.add(self, "%s (%s)\n" % (widgetName, self.__class__.__name__))
        
        #
        # add properties shared by all BlissWidgets
        #
        self.addProperty('fontSize', 'string', str(self.font().pointSize()))
        #self.addProperty("alignment", "combo", ("none", "top center", "top left", "top right", "bottom center", "bottom left", "bottom right", "center", "left", "right"), "none")
        self.addProperty('instanceAllowAlways', 'boolean', False)#, hidden=True)
        self.addProperty('instanceAllowConnected', 'boolean', False)#, hidden=True)

        #
        # connect signals / slots
        #
        dispatcher.connect(self.__hardwareObjectDiscarded, 'hardwareObjectDiscarded', HardwareRepository.HardwareRepository())
 
        self.defineSlot('enable_widget', ())
    def init(self):
        self.centringMethods={MicrodiffPX2.MANUAL3CLICK_MODE: self.start3ClickCentring,\
            MicrodiffPX2.C3D_MODE: self.startAutoCentring,
            MicrodiffPX2.MOVE_TO_BEAM_MODE: self.startMoveToBeamCentring }
        self.cancelCentringMethods = {}
        self.flexibleMethods={MicrodiffPX2.MANUAL3CLICK_MODE:False,\
            MicrodiffPX2.C3D_MODE: False,
            MicrodiffPX2.MOVE_TO_BEAM_MODE: True }

        #self.moveToCentredProcedure = None
        #self.snapshotsProcedure = None

        self.centringStatus = {"valid": False}

        self.phiMotor = self.getDeviceByRole('phi')
        self.phizMotor = self.getDeviceByRole('phiz')
        self.phiyMotor = self.getDeviceByRole('phiy')
        self.zoomMotor = self.getDeviceByRole('zoom')
        self.lightMotor = self.getDeviceByRole('lightLevel')
        self.lightWago = self.getDeviceByRole('lightInOut')
        self.focusMotor = self.getDeviceByRole('focus')
        self.sampleXMotor = self.getDeviceByRole('sampx')
        self.sampleYMotor = self.getDeviceByRole('sampy')
        self.camera = self.getDeviceByRole('camera')
        self.md2 = PyTango.DeviceProxy('i11-ma-cx1/ex/md2')  #MS 6.4.2012
        print(
            'MS debug 15.11.2012 MicrodiffPX2(Equipment) self.phiMotor.tangoname'
        )
        print(self.phiMotor.tangoname)

        self.x_calib = self.addChannel(
            {
                "type": "tango",
                "tangoname": self.phiMotor.tangoname,
                "name": "x_calib",
                "polling": 1000
            }, "CoaxCamScaleX")  #, "polling":"events" }, "CoaxCamScaleX")
        #self.x_calib = self.addChannel({ "type":"tango", "tangoname": 'i11-ma-cx1/ex/md2', "name":"x_calib" }, "CoaxCamScaleX")
        self.y_calib = self.addChannel(
            {
                "type": "tango",
                "tangoname": self.phiMotor.tangoname,
                "name": "y_calib",
                "polling": 1000
            }, "CoaxCamScaleY")  #, "polling":"events" }, "CoaxCamScaleY")
        #self.y_calib = self.addChannel({ "type":"tango", "tangoname": 'i11-ma-cx1/ex/md2', "name":"y_calib" }, "CoaxCamScaleY")
        self.x_calib.connectSignal("update", self._update_x_calib)
        self.y_calib.connectSignal("update", self._update_y_calib)
        #self.connect(self.pixelsPerMmY, "update", self._update_y_calib)
        #self.connect(self.pixelsPerMmZ, "update", self._update_x_calib)
        self.moveMultipleMotors = self.addCommand(
            {
                "type": "tango",
                "tangoname": self.phiMotor.tangoname,
                "name": "move_multiple_motors"
            }, "SyncMoveMotors")
        sc_prop = self.getProperty("samplechanger")
        if sc_prop is not None:
            try:
                self.sampleChanger = HardwareRepository.HardwareRepository(
                ).getHardwareObject(sc_prop)
            except:
                pass

        if self.phiMotor is not None:
            self.connect(self.phiMotor, 'stateChanged',
                         self.phiMotorStateChanged)
            self.phiMotor.motorState = 2
        else:
            logging.getLogger("HWR").error(
                'Microdiff: phi motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.phizMotor is not None:
            self.connect(self.phizMotor, 'stateChanged',
                         self.phizMotorStateChanged)
            self.connect(self.phizMotor, 'positionChanged',
                         self.phizMotorMoved)
            self.phizMotor.motorState = 2
        else:
            logging.getLogger("HWR").error(
                'Microdiff: phiz motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.phiyMotor is not None:
            self.connect(self.phiyMotor, 'stateChanged',
                         self.phiyMotorStateChanged)
            self.connect(self.phiyMotor, 'positionChanged',
                         self.phiyMotorMoved)
            self.phiyMotor.motorState = 2
        else:
            logging.getLogger("HWR").error(
                'Microdiff: phiy motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.zoomMotor is not None:
            self.connect(self.zoomMotor, 'predefinedPositionChanged',
                         self.zoomMotorPredefinedPositionChanged)
            self.connect(self.zoomMotor, 'stateChanged',
                         self.zoomMotorStateChanged)
        else:
            logging.getLogger("HWR").error(
                'Microdiff: zoom motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.sampleXMotor is not None:
            self.connect(self.sampleXMotor, 'stateChanged',
                         self.sampleXMotorStateChanged)
            self.connect(self.sampleXMotor, 'positionChanged',
                         self.sampleXMotorMoved)
            self.sampleXMotor.motorState = 2
        else:
            logging.getLogger("HWR").error(
                'Microdiff: sampx motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.sampleYMotor is not None:
            self.connect(self.sampleYMotor, 'stateChanged',
                         self.sampleYMotorStateChanged)
            self.connect(self.sampleYMotor, 'positionChanged',
                         self.sampleYMotorMoved)
            self.sampleYMotor.motorState = 2
        else:
            logging.getLogger("HWR").error(
                'Microdiff: sampy motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.camera is None:
            logging.getLogger("HWR").error(
                'Microdiff: camera is not defined in minidiff equipment %s',
                str(self.name()))
        else:
            self.imgWidth, self.imgHeight = self.camera.getWidth(
            ), self.camera.getHeight()
        if self.sampleChanger is None:
            logging.getLogger("HWR").warning(
                'Microdiff: sample changer is not defined in minidiff equipment %s',
                str(self.name()))
        else:
            try:
                self.connect(self.sampleChanger, 'sampleIsLoaded',
                             self.sampleChangerSampleIsLoaded)
            except:
                logging.getLogger("HWR").exception(
                    'Microdiff: could not connect to sample changer smart magnet'
                )
        try:
            self.auto_loop_centring = self.getChannelObject(
                "auto_centring_flag")
        except KeyError:
            logging.getLogger("HWR").warning(
                "MiniDiff: automatic loop centring will not auto start after SC loading"
            )
        else:
            self.auto_loop_centring.connectSignal("update",
                                                  self.do_auto_loop_centring)
示例#6
0
    def init(self):
        self.centringMethods={self.MANUAL3CLICK_MODE: self.start3ClickCentring,\
            self.C3D_MODE: self.startAutoCentring }
        self.cancelCentringMethods = {}

        self.currentCentringProcedure = None
        self.currentCentringMethod = None

        self.centringStatus = {"valid": False}

        try:
            phiz_ref = self["centringReferencePosition"].getProperty("phiz")
        except:
            phiz_ref = None
        self.phiMotor = self.getDeviceByRole('phi')
        self.phizMotor = self.getDeviceByRole('phiz')
        self.phiyMotor = self.getDeviceByRole("phiy")
        self.zoomMotor = self.getDeviceByRole('zoom')
        self.lightMotor = self.getDeviceByRole('light')
        self.focusMotor = self.getDeviceByRole('focus')
        self.sampleXMotor = self.getDeviceByRole("sampx")
        self.sampleYMotor = self.getDeviceByRole("sampy")
        self.camera = self.getDeviceByRole('camera')
        try:
            phiDirection = self.phiMotor.getProperty("direction")
            if phiDirection == None:
                phiDirection = 1
        except:
            phiDirection = 1

        self.centringPhi = sample_centring.CentringMotor(
            self.phiMotor, direction=phiDirection)
        self.centringPhiz = sample_centring.CentringMotor(
            self.phizMotor, reference_position=phiz_ref)
        self.centringPhiy = sample_centring.CentringMotor(self.phiyMotor,
                                                          direction=-1)
        self.centringSamplex = sample_centring.CentringMotor(self.sampleXMotor)
        self.centringSampley = sample_centring.CentringMotor(self.sampleYMotor)

        try:
            self.md2 = PyTango.DeviceProxy(
                self.tangoname)  #'i11-ma-cx1/ex/md2')
        except:
            logging.error("MiniDiffPX2 / Cannot connect to tango device: %s ",
                          self.tangoname)
        else:
            self.md2_ready = True

        # some defaults
        self.anticipation = 1
        self.collect_phaseposition = 'DataCollection'

        sc_prop = self.getProperty("samplechanger")
        if sc_prop is not None:
            try:
                self.sampleChanger = HardwareRepository.HardwareRepository(
                ).getHardwareObject(sc_prop)
            except:
                pass
        wl_prop = self.getProperty("wagolight")
        if wl_prop is not None:
            try:
                self.lightWago = HardwareRepository.HardwareRepository(
                ).getHardwareObject(wl_prop)
            except:
                pass
        aperture_prop = self.getProperty("aperture")
        if aperture_prop is not None:
            try:
                self.aperture = HardwareRepository.HardwareRepository(
                ).getHardwareObject(aperture_prop)
            except:
                pass

        if self.phiMotor is not None:
            self.connect(self.phiMotor, 'stateChanged',
                         self.phiMotorStateChanged)
            self.connect(self.phiMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: phi motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.phizMotor is not None:
            self.connect(self.phizMotor, 'stateChanged',
                         self.phizMotorStateChanged)
            self.connect(self.phizMotor, 'positionChanged',
                         self.phizMotorMoved)
            self.connect(self.phizMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: phiz motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.phiyMotor is not None:
            self.connect(self.phiyMotor, 'stateChanged',
                         self.phiyMotorStateChanged)
            self.connect(self.phiyMotor, 'positionChanged',
                         self.phiyMotorMoved)
            self.connect(self.phiyMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: phiy motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.zoomMotor is not None:
            self.connect(self.zoomMotor, 'predefinedPositionChanged',
                         self.zoomMotorPredefinedPositionChanged)
            self.connect(self.zoomMotor, 'stateChanged',
                         self.zoomMotorStateChanged)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: zoom motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.sampleXMotor is not None:
            self.connect(self.sampleXMotor, 'stateChanged',
                         self.sampleXMotorStateChanged)
            self.connect(self.sampleXMotor, 'positionChanged',
                         self.sampleXMotorMoved)
            self.connect(self.sampleXMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: sampx motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.sampleYMotor is not None:
            self.connect(self.sampleYMotor, 'stateChanged',
                         self.sampleYMotorStateChanged)
            self.connect(self.sampleYMotor, 'positionChanged',
                         self.sampleYMotorMoved)
            self.connect(self.sampleYMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: sampy motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.camera is None:
            logging.getLogger("HWR").error(
                'MiniDiff: camera is not defined in minidiff equipment %s',
                str(self.name()))
        else:
            self.imgWidth, self.imgHeight = self.camera.getWidth(
            ), self.camera.getHeight()
        if self.sampleChanger is None:
            logging.getLogger("HWR").warning(
                'MiniDiff: sample changer is not defined in minidiff equipment %s',
                str(self.name()))
        else:
            try:
                self.connect(self.sampleChanger, 'sampleIsLoaded',
                             self.sampleChangerSampleIsLoaded)
            except:
                logging.getLogger("HWR").exception(
                    'MiniDiff: could not connect to sample changer smart magnet'
                )
        if self.lightWago is not None:
            self.connect(self.lightWago, 'wagoStateChanged',
                         self.wagoLightStateChanged)
        else:
            logging.getLogger("HWR").warning(
                'MiniDiff: wago light is not defined in minidiff equipment %s',
                str(self.name()))
        if self.aperture is not None:
            self.connect(self.aperture, 'predefinedPositionChanged',
                         self.apertureChanged)
            self.connect(self.aperture, 'positionReached',
                         self.apertureChanged)
示例#7
0
    def init(self):
        self.centringMethods={MiniDiff.MANUAL3CLICK_MODE: self.start3ClickCentring,\
            MiniDiff.C3D_MODE: self.startAutoCentring }
        self.cancelCentringMethods = {}

        self.currentCentringProcedure = None
        self.currentCentringMethod = None

        self.centringStatus = {"valid": False}

        try:
            phiz_ref = self["centringReferencePosition"].getProperty("phiz")
        except:
            phiz_ref = None

        self.phiMotor = self.getDeviceByRole('phi')
        self.phizMotor = self.getDeviceByRole('phiz')
        self.phiyMotor = self.getObjectByRole("phiy")
        self.zoomMotor = self.getDeviceByRole('zoom')
        self.lightMotor = self.getDeviceByRole('light')
        self.focusMotor = self.getDeviceByRole('focus')
        self.sampleXMotor = self.getDeviceByRole("sampx")
        self.sampleYMotor = self.getDeviceByRole("sampy")
        self.camera = self.getDeviceByRole('camera')
        self.kappaMotor = self.getDeviceByRole('kappa')
        self.kappaPhiMotor = self.getDeviceByRole('kappa_phi')
        self.beam_info = self.getObjectByRole('beam_info')

        # mh 2013-11-05:why is the channel read directly? disabled for the moment
        # self.camera.addChannel({ 'type': 'tango', 'name': 'jpegImage' }, "JpegImage")

        self.centringPhi = sample_centring.CentringMotor(self.phiMotor,
                                                         direction=-1)
        self.centringPhiz = sample_centring.CentringMotor(
            self.phizMotor, reference_position=phiz_ref)
        self.centringPhiy = sample_centring.CentringMotor(self.phiyMotor)
        self.centringSamplex = sample_centring.CentringMotor(self.sampleXMotor)
        self.centringSampley = sample_centring.CentringMotor(self.sampleYMotor)

        hwr = HardwareRepository.HardwareRepository()
        sc_prop = self.getProperty("samplechanger")
        if sc_prop is not None:
            try:
                self.sampleChanger = hwr.getHardwareObject(sc_prop)
            except:
                pass
        wl_prop = self.getProperty("wagolight")
        if wl_prop is not None:
            try:
                self.lightWago = hwr.getHardwareObject(wl_prop)
            except:
                pass
        aperture_prop = self.getProperty("aperture")
        if aperture_prop is not None:
            try:
                self.aperture = hwr.getHardwareObject(aperture_prop)
            except:
                pass

        if self.phiMotor is not None:
            self.connect(self.phiMotor, 'stateChanged',
                         self.phiMotorStateChanged)
            self.connect(self.phiMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: phi motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.phizMotor is not None:
            self.connect(self.phizMotor, 'stateChanged',
                         self.phizMotorStateChanged)
            self.connect(self.phizMotor, 'positionChanged',
                         self.phizMotorMoved)
            self.connect(self.phizMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: phiz motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.phiyMotor is not None:
            self.connect(self.phiyMotor, 'stateChanged',
                         self.phiyMotorStateChanged)
            self.connect(self.phiyMotor, 'positionChanged',
                         self.phiyMotorMoved)
            self.connect(self.phiyMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: phiy motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.zoomMotor is not None:
            self.connect(self.zoomMotor, 'predefinedPositionChanged',
                         self.zoomMotorPredefinedPositionChanged)
            self.connect(self.zoomMotor, 'stateChanged',
                         self.zoomMotorStateChanged)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: zoom motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.sampleXMotor is not None:
            self.connect(self.sampleXMotor, 'stateChanged',
                         self.sampleXMotorStateChanged)
            self.connect(self.sampleXMotor, 'positionChanged',
                         self.sampleXMotorMoved)
            self.connect(self.sampleXMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: sampx motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.sampleYMotor is not None:
            self.connect(self.sampleYMotor, 'stateChanged',
                         self.sampleYMotorStateChanged)
            self.connect(self.sampleYMotor, 'positionChanged',
                         self.sampleYMotorMoved)
            self.connect(self.sampleYMotor, "positionChanged",
                         self.emitDiffractometerMoved)
        else:
            logging.getLogger("HWR").error(
                'MiniDiff: sampx motor is not defined in minidiff equipment %s',
                str(self.name()))
        if self.camera is None:
            logging.getLogger("HWR").error(
                'MiniDiff: camera is not defined in minidiff equipment %s',
                str(self.name()))
        else:
            self.imgWidth, self.imgHeight = self.camera.getWidth(
            ), self.camera.getHeight()
        if self.sampleChanger is None:
            logging.getLogger("HWR").warning(
                'MiniDiff: sample changer is not defined in minidiff equipment %s',
                str(self.name()))
        else:
            try:
                self.connect(self.sampleChanger, 'sampleIsLoaded',
                             self.sampleChangerSampleIsLoaded)
            except:
                logging.getLogger("HWR").exception(
                    'MiniDiff: could not connect to sample changer smart magnet'
                )
        if self.lightWago is not None:
            self.connect(self.lightWago, 'wagoStateChanged',
                         self.wagoLightStateChanged)
        else:
            logging.getLogger("HWR").warning(
                'MiniDiff: wago light is not defined in minidiff equipment %s',
                str(self.name()))
        if self.aperture is not None:
            self.connect(self.aperture, 'predefinedPositionChanged',
                         self.apertureChanged)
            self.connect(self.aperture, 'positionReached',
                         self.apertureChanged)
示例#8
0
import unittest
from HardwareRepository import HardwareRepository
from HardwareRepository.BaseHardwareObjects import HardwareObject


__credits__ = ["MXCuBE colaboration"]
__version__ = "2.2."

cwd = os.getcwd()
hwr_server = cwd +  "/ExampleFiles/HardwareObjects.xml"

print "==============================================================="
print "MXCuBE home directory: %s" % cwd
print "Hardware repository: %s" % hwr_server
HardwareRepository.setHardwareRepositoryServer(hwr_server)
hardware_repository = HardwareRepository.HardwareRepository()
hardware_repository.connect()
HardwareRepository.addHardwareObjectsDirs([cwd + "/HardwareObjects"])
unittest_hwobj = hardware_repository.getHardwareObject("unittest")
if unittest_hwobj is not None:
    print "UnitTest hardware object loaded"
else:
    print "Unable to load UnitTest hardware object!"
    print "Check if unittest.xml is in %s" % hwr_server
print "==============================================================="

class TestException(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):