예제 #1
0
파일: signals.py 프로젝트: mguijarr/mxcube3
def motor_event_callback(*args, **kwargs):
    # logging.getLogger('HWR').debug('[MOTOR CALLBACK]')
    # logging.getLogger("HWR").debug(kwargs)
    # logging.getLogger("HWR").debug(args)
    signal = kwargs['signal']
    sender = str(kwargs['sender'].__class__).split('.')[0]

    motors_info = Utils.get_centring_motors_info() 

    motors_info.update(Utils.get_light_state_and_intensity())

    motors_info['pixelsPerMm'] = mxcube.diffractometer.get_pixels_per_mm()

    aux = {}
    for pos in mxcube.diffractometer.savedCentredPos:
            aux.update({pos['posId']: pos})

    #  sending all motors position/status, and the current centred positions
    msg = {'Signal': signal,
           'Message': signal,
           'Motors': motors_info,
           'CentredPositions': aux,
           'Data': args[0] if len(args) == 1 else args}
    # logging.getLogger('HWR').debug('[MOTOR CALLBACK]   ' + str(msg))

    try:
        socketio.emit('Motors', msg, namespace='/hwr')
    except Exception:
        logging.getLogger("HWR").error('error sending message: %s' + str(msg))
예제 #2
0
파일: signals.py 프로젝트: bolmsten/mxcube3
def motor_event_callback(*args, **kwargs):
    # logging.getLogger('HWR').debug('[MOTOR CALLBACK]')
    # logging.getLogger("HWR").debug(kwargs)
    # logging.getLogger("HWR").debug(args)
    signal = kwargs['signal']
    sender = str(kwargs['sender'].__class__).split('.')[0]

    motors_info = Utils.get_centring_motors_info() 

    motors_info.update(Utils.get_light_state_and_intensity())

    motors_info['pixelsPerMm'] = mxcube.diffractometer.get_pixels_per_mm()

    aux = {}
    for pos in mxcube.diffractometer.savedCentredPos:
            aux.update({pos['posId']: pos})

    #  sending all motors position/status, and the current centred positions
    msg = {'Signal': signal,
           'Message': signal,
           'Motors': motors_info,
           'CentredPositions': aux,
           'Data': args[0] if len(args) == 1 else args}
    # logging.getLogger('HWR').debug('[MOTOR CALLBACK]   ' + str(msg))

    try:
        socketio.emit('Motors', msg, namespace='/hwr')
    except Exception:
        logging.getLogger("HWR").error('error sending message: %s' + str(msg))
예제 #3
0
def get_movables_state():
    ret = Utils.get_centring_motors_info()

    ret.update(Utils.get_light_state_and_intensity())

    resp = jsonify(ret)
    resp.status_code = 200
    return resp
예제 #4
0
def get_movables_state():
    ret = Utils.get_centring_motors_info()

    ret.update(Utils.get_light_state_and_intensity())

    resp = jsonify(ret)
    resp.status_code = 200
    return resp
예제 #5
0
def get_movables_state():
    ret = {}

    for movable in ['Phi', 'Focus', 'PhiZ', 'PhiY','Sampx', 'Sampy', 'Zoom']:
        ret.update(Utils.get_movable_state_and_position(movable))

    ret.update(Utils.get_light_state_and_intensity())

    resp = jsonify(ret)
    resp.status_code = 200
    return resp
예제 #6
0
def motor_event_callback(*args, **kwargs):
    #logging.getLogger('HWR').debug('[MOTOR CALLBACK]')
    #logging.getLogger("HWR").debug(kwargs) 
    #logging.getLogger("HWR").debug(args) 
    signal = kwargs['signal']
    sender = str(kwargs['sender'].__class__).split('.')[0]

    motors_info = dict()

    for name in ['Phi', 'Focus', 'PhiZ', 'PhiY', 'Zoom', 'BackLightSwitch','BackLight','FrontLightSwitch', 'FrontLight','Sampx', 'Sampy']:
        motors_info.update(Utils.get_movable_state_and_position(name))

    motors_info['pixelsPerMm'] = mxcube.diffractometer.get_pixels_per_mm()

    aux = {}
    for p in mxcube.diffractometer.savedCentredPos:
            aux.update({p['posId']:p})

    ## sending all motors position/status, and the current centred positions
    msg = {'Signal': signal,'Message': signal, 'Motors':motors_info, 'CentredPositions': aux, 'Data': args[0] if len(args) ==1 else args}
    #logging.getLogger('HWR').debug('[MOTOR CALLBACK]   ' + str(msg))
    try:
        socketio.emit('Motors', msg, namespace='/hwr')
    except Exception:
        logging.getLogger("HWR").error('error sending message: %s'+str(msg))

    try:
        msg = { "message": sender +':'+signal, "severity": 'INFO', "timestamp":time.asctime(), "logger":'HWR', "stack_trace":'' }
        socketio.emit('log_record', msg, namespace='/logging')
    except Exception:
        logging.getLogger("HWR").error('error sending message: %s'+str(msg))
예제 #7
0
        def state_cb(state, motor=motor, **kw):
            movable = Utils.get_movable_state_and_position(motor)

            if movable:
                signals.motor_state_callback(movable[motor], **kw)
            else:
                logging.getLogger('HWR').exception("Could not call state callback for %s" % motor)
예제 #8
0
        def state_cb(state, motor=motor, **kw):
            movable = Utils.get_movable_state_and_position(motor)

            if movable:
                signals.motor_state_callback(movable[motor], **kw)
            else:
                logging.getLogger('HWR').exception(
                    "Could not call state callback for %s" % motor)
예제 #9
0
def get_status_of_id(id):
    """
    Get position and status of the given element
        :parameter id: moveable to get its status, 'Phi', 'Focus', 'PhiZ', 'PhiY', 'Zoom', 'BackLightSwitch','BackLight','FrontLightSwitch', 'FrontLight','Sampx', 'Sampy'
        :response Content-type: application/json, {motorname: {'Status': status, 'position': position} }
        :statuscode: 200: no error
        :statuscode: 409: error
    """
    if 'Light' in id:
        ret = Utils.get_light_state_and_intensity()
    else:
        ret = Utils.get_movable_state_and_position(id)
    if ret:
        resp = jsonify(ret)
        resp.status_code = 200
        return resp
    else:
        return Response(status=409)
예제 #10
0
def get_status_of_id(elem_id):
    """
    Get position and status of the given element
        :parameter id: moveable to get its status, 'Phi', 'Focus', 'PhiZ',
        'PhiY', 'Zoom', 'BackLightSwitch','BackLight','FrontLightSwitch',
        'FrontLight','Sampx', 'Sampy'
        :response Content-type: application/json, {motorname:
            {'Status': status, 'position': position} }
        :statuscode: 200: no error
        :statuscode: 409: error
    """
    if 'Light' in elem_id:
        ret = Utils.get_light_state_and_intensity()
    else:
        ret = Utils.get_movable_state_and_position(elem_id)
    if ret:
        resp = jsonify(ret)
        resp.status_code = 200
        return resp
    else:
        return Response(status=409)
예제 #11
0
파일: Login.py 프로젝트: milanprica/mxcube3
def loginInfo():
    """
    Retrieve session/login info
     :response Content-Type: application/json, {"synchrotron_name": synchrotron_name, "beamline_name": beamline_name,
                    "loginType": loginType, "loginRes": {'status':{ "code": "ok", "msg": msg }, 'Proposal': proposal, 'session': todays_session, "local_contact": local_contact, "person": someone, "laboratory": a_laboratory']} }
    """
    loginInfo = session.get("loginInfo")
 
    if loginInfo is not None:
        loginInfo["loginRes"] = mxcube.db_connection.login(loginInfo["loginID"], loginInfo["password"])
        session['loginInfo'] = loginInfo
  
    mxcube.queue = Utils.get_queue(session) 
 
    return jsonify(
                    { "synchrotron_name": mxcube.session.synchrotron_name,
                      "beamline_name": mxcube.session.beamline_name,
                      "loginType": mxcube.db_connection.loginType.title(),
                      "loginRes": convert_to_dict(loginInfo["loginRes"] if loginInfo is not None else {}),
                      "queue": Queue.serializeQueueToJson()
                    }
                  )
예제 #12
0
def init_signals():
    """
    Connect all the relevant hwobj signals with the corresponding
    callback method.
    """
    dm = mxcube.diffractometer

    for motor in Utils.get_centring_motors():

        @Utils.RateLimited(3)
        def pos_cb(pos, motor=motor, **kw):
            movable = Utils.get_movable_state_and_position(motor)

            if movable:
                signals.motor_position_callback(movable[motor])
            else:
                logging.getLogger('HWR').exception(
                    "Could not call position callback for %s" % motor)

        def state_cb(state, motor=motor, **kw):
            movable = Utils.get_movable_state_and_position(motor)

            if movable:
                signals.motor_state_callback(movable[motor], **kw)
            else:
                logging.getLogger('HWR').exception(
                    "Could not call state callback for %s" % motor)

        setattr(dm, "_%s_pos_callback" % motor, pos_cb)
        setattr(dm, "_%s_state_callback" % motor, state_cb)
        dm.connect(dm.getObjectByRole(motor), "positionChanged", pos_cb)
        dm.connect(dm.getObjectByRole(motor), "stateChanged", state_cb)

    for motor in ['FrontLight', 'BackLight']:

        def state_cb(state, motor=motor, **kw):
            movable = Utils.get_movable_state_and_position(motor)
            signals.motor_state_callback(movable[motor], **kw)
            signals.motor_state_callback(movable[motor + "Switch"], **kw)

        setattr(dm, "_%s_state_callback" % motor, state_cb)

        try:
            motor_hwobj = dm.getObjectByRole(motor)
            motor_hwobj.connect(motor_hwobj, 'positionChanged', state_cb)

            if hasattr(motor_hwobj, "actuatorIn"):
                motor_hwobj = dm.getObjectByRole(motor)
                motor_hwobj.connect(motor_hwobj, 'actuatorStateChanged',
                                    state_cb)
            else:
                motor_sw_hwobj = dm.getObjectByRole(motor + 'Switch')
                motor_sw_hwobj.connect(motor_sw_hwobj, 'actuatorStateChanged',
                                       state_cb)

        except Exception as ex:
            logging.getLogger('HWR').exception(str(ex))

    dm.connect("centringStarted", signals.centring_started)
    dm.connect(dm, "centringSuccessful", wait_for_centring_finishes)
    dm.connect(dm, "centringFailed", wait_for_centring_finishes)

    global CLICK_LIMIT
    CLICK_LIMIT = int(mxcube.beamline.\
                      getProperty('click_centring_num_clicks') or 3)
예제 #13
0
 def state_cb(state, motor=motor, **kw):
     movable = Utils.get_movable_state_and_position(motor)
     signals.motor_state_callback(movable[motor], **kw)
     signals.motor_state_callback(movable[motor + "Switch"], **kw)
예제 #14
0
 def state_cb(state, motor=motor, **kw):
     movable = Utils.get_movable_state_and_position(motor)
     signals.motor_state_callback(movable[motor], **kw)
     signals.motor_state_callback(movable[motor + "Switch"], **kw)