Exemplo n.º 1
0
def all_connected(with_m2=False):
    motors = [
        dm3_bct,
        xafs_yu,
        xafs_ydo,
        xafs_ydi,
        m3_yu,
        m3_ydo,
        m3_ydi,
        m3_xu,
        m3_xd,
    ]
    if with_m2 is True:
        motors.extend([m2_yu, m2_ydo, m2_ydi])
    ok = True
    for m in motors:
        if m.connected is False:
            print(disconnected_msg(f'{m.name} is not connected'))
            for walk in m.walk_signals(include_lazy=False):
                if walk.item.connected is False:
                    print(
                        disconnected_msg(
                            f'      {walk.item.name} is a disconnected PV'))
            print(
                whisper(
                    f'try: {m.name} = {m.__class__}("{m.prefix}", name={m.name})'
                ))
            ok = False
    return ok
Exemplo n.º 2
0
 def _pressure(self):
     if self.connected is False:
         return(disconnected_msg('?????'))
     if self.pressure.get() == 'OFF':
         return(disconnected_msg(-1.1e-15))
     if float(self.pressure.get()) > 1e-1:
         return warning_msg(self.pressure.get())
     if float(self.pressure.get()) > 6e-3:
         return error_msg(self.pressure.get())
     return(self.pressure.get())
Exemplo n.º 3
0
 def do_ChangeXtals(self):
     if user_ns['dcm']._crystal == '111':
         print(
             go_msg('You would like to change from the ') +
             whisper('Si(111)') + go_msg(' to the ') + bold_msg('Si(311)') +
             go_msg(' crystals...\n'))
         print(disconnected_msg('yield from change_xtals("311")'))
     else:
         print(
             go_msg('You would like to change from the ') +
             whisper('Si(311)') + go_msg(' to the ') + bold_msg('Si(111)') +
             go_msg(' crystals...\n'))
         print(disconnected_msg('yield from change_xtals("111")'))
     yield from null()
Exemplo n.º 4
0
    def _pressure(self):
        #print(self.pressure.get())
        #print(type(self.pressure.get()))
        if self.connected is False:
            return(disconnected_msg('?????'))
        if self.pressure.get() == 'OFF':
            return(disconnected_msg(-1.1E-15))

        if type(self.pressure.get()) is str and self.pressure.get() == 'LO<E-11':
            return whisper('1.00e-11')
        if float(self.pressure.get()) > 1e-6:
            return error_msg(self.pressure.get())
        if float(self.pressure.get()) > 1e-8:
            return warning_msg(self.pressure.get())
        return(self.pressure.get())
Exemplo n.º 5
0
    def do_ChangeEdge(self):
        print(go_msg('You would like to change to a different edge...\n'))

        el = input(" What element? ")
        el = el.capitalize()
        if el == '':
            print(whisper('doing nothing'))
            return (yield from null())
        if el not in ELEMENTS:
            print(error_msg(f'{el} is not an element'))
            return (yield from null())

        if Z_number(el) < 46:
            default_ed = 'K'
            prompt = go_msg('K') + '/L3/L2/L1'
        else:
            default_ed = 'L3'
            prompt = 'K/' + go_msg('L3') + '/L2/L1'
        ed = input(f' What edge? [{prompt}] ')
        ed = ed.capitalize()
        if ed not in ('K', 'L3', 'L2', 'L1'):
            ed = default_ed

        focus = input(' Focused beam? [y/N] ')
        if focus.lower() == 'y':
            focus = True
        else:
            focus = False

        print(
            disconnected_msg(
                f'yield from change_edge("{el}", focus={focus}, edge="{ed}")'))
        yield from null()
Exemplo n.º 6
0
 def do_SetupXRD(self):
     print(go_msg('You would like to set up for XRD...\n'))
     print(
         disconnected_msg(
             'yield from change_edge("Ni", xrd=True, energy=8600)'))
     #yield from change_edge("Ni", xrd=True, energy=8600)
     yield from null()
Exemplo n.º 7
0
 def do_RunMacro(self):
     print(go_msg('You would like to run a measurement macro...\n'))
     macro = present_options('py')
     if macro is None:
         return
     ipython = get_ipython()
     fullpath = os.path.join(user_ns['BMMuser'].folder, macro)
     ipython.magic(f'run -i \'{fullpath}\'')
     print(disconnected_msg(f'yield from {macro[:-3]}()'))
     yield from null()
Exemplo n.º 8
0
 def _state(self, info=False):
     t = "%.1f" % self.temperature.get()
     if self.connected is False:
         return(disconnected_msg('?????'))
     if self.temperature.get() > self.alarm.get():
         return(error_msg(t))
     if self.temperature.get() > self.warning.get():
         return(warning_msg(t))
     if info is True and self.temperature.get() > (0.5 * self.warning.get()):
         return(info_msg(t))
     return(t)
Exemplo n.º 9
0
    def _pressure(self):
        #print(self.pressure.get())
        #print(type(self.pressure.get()))
        if self.pressure.get() == 'OFF':
            return (disconnected_msg(-1.1E-15))

        if float(self.pressure.get()) > 1e-6:
            return error_msg(self.pressure.get())
        if float(self.pressure.get()) > 1e-8:
            return warning_msg(self.pressure.get())
        return (self.pressure.get())
Exemplo n.º 10
0
    def _pressure(self, num=None):
        if self.connected is False:
            return(disconnected_msg('?????'))
        if num is None:
            num = 1
        if num < 1:
            num = 1
        if num > 6:
            num = 6
        sgnl = getattr(self, 'p'+str(num))
        #print(self.pressure.get())
        #print(type(self.pressure.get()))
        if sgnl.get() == 'OFF':
            return(disconnected_msg(-1.1E-15))

        if float(sgnl.get()) > 1e-6:
            return error_msg(self.pressure.get())
        if float(sgnl.get()) > 1e-8:
            return warning_msg(self.pressure.get())
        return(sgnl.get())
Exemplo n.º 11
0
 def _current(self):
     if self.connected is False:
         return(disconnected_msg('?????'))
     curr = float(self.current.get())
     if curr > 2e-3:
         out = '%.1f' % (1e3*curr)
         return(error_msg(out))
     if curr > 5e-4:
         out = '%.1f' % (1e3*curr)
         return(warning_msg(out))
     out = '%.1f' % (1e6*curr)
     return(out)
Exemplo n.º 12
0
def ocd(text, signal):
    '''Indicated open/close/disconnected state with suitable text coloring.
    '''
    outtext = text
    try:
        if signal.connected is False:
            outtext += disconnected_msg('disconnected ')
        elif signal.get() == 1:
            outtext += 'enabled      '
        else:
            outtext += error_msg('disabled      ')
    except:
        outtext += whisper('unavailable   ')
    return outtext
Exemplo n.º 13
0
def report(text, level=None, slack=False):
    '''Print a string to:
      * the log file
      * the screen
      * the BMM beamtime slack channel

    Report level decorations  on screen:

      * 'error' (red)
      * 'warning' (yellow)
      * 'info' (brown)
      * 'url' (undecorated)
      * 'bold' (bright white)
      * 'verbosebold' (bright cyan)
      * 'list' (cyan)
      * 'disconnected' (purple)
      * 'whisper' (gray)

    not matching a report level will be undecorated
    '''
    BMMuser = user_ns['BMMuser']
    BMM_log_info(text)
    if color:  # test that color is sensible...
        if level == 'error':
            print(error_msg(text))
        elif level == 'warning':
            print(warning_msg(text))
        elif level == 'info':
            print(info_msg(text))
        elif level == 'url':
            print(url_msg(text))
        elif level == 'bold':
            print(bold_msg(text))
        elif level == 'verbosebold':
            print(verbosebold_msg(text))
        elif level == 'disconnected':
            print(disconnected_msg(text))
        elif level == 'list':
            print(list_msg(text))
        elif level == 'whisper':
            print(whisper(text))
        else:
            print(text)
    else:
        print(text)
    if BMMuser.use_slack and slack:
        post_to_slack(text)
Exemplo n.º 14
0
 def _current(self, num=None):
     if self.connected is False:
         return(disconnected_msg('?????'))
     if num is None:
         num = 1
     if num < 1:
         num = 1
     if num > 6:
         num = 6
     sgnl = getattr(self, 'c'+str(num))
     curr = float(sgnl.get())
     if curr > 2e-3:
         out = '%.1f' % (1e3*curr)
         return(error_msg(out))
     if curr > 5e-4:
         out = '%.1f' % (1e3*curr)
         return(warning_msg(out))
     out = '%.1f' % (1e6*curr)
     return(out)
Exemplo n.º 15
0
def check_for_synaxis():
    '''A disconnected motor (due to IOC or controller not running) will be
    defined as a SynAxis. This does a test for that situation and
    reports about it at startup.  It also sets BMMuser.syns to True so
    things like motor_status() behave non-disastrously.
    '''
    BMMuser.syns = False
    syns = []
    for m in mcs8_motors:
        if 'SynAxis' in f'{m}':
            syns.append(m.name)
    if len(syns) > 0:
        BMMuser.syns = True
        text = 'The following are disconnected & defined as simulated motors:\n\n'
        text += '\n'.join(
            disconnected_msg(x)
            for x in textwrap.wrap(', '.join(syns))) + '\n\n'
        text += 'This allows bsui to operate normally, but do not expect anything\n'
        text += 'involving those motors to work correctly.\n'
        text += whisper(
            '(This likely means that an IOC or a motor controller (or both) are off.)'
        )
        boxedtext('Disconnected motors', text, 'red', width=74)
Exemplo n.º 16
0
 def do_RockingCurve(self):
     print(go_msg('You would like to measure a rocking curve scan...\n'))
     print(disconnected_msg('yield from rocking_curve()'))
     yield from null()
Exemplo n.º 17
0
 def do_SlitHeight(self):
     print(go_msg('You would like to set the slit height...\n'))
     print(disconnected_msg('yield from slit_height()'))
     yield from null()