Exemple #1
0
 def __init__(
     self,
     *args,
     write_path: str,
     always_acquire: bool = True,
     **kwargs,
 ):
     super().__init__(*args, **kwargs)
     self.hutch_name = get_hutch_name()
     self.always_acquire = always_acquire
     self.num_images_per_point = 1
     self.hdf51.write_path_template = write_path
     self.hdf51.stage_sigs['file_template'] = '%s%s_%03d.h5'
     self.hdf51.stage_sigs['file_write_mode'] = 'Stream'
     del self.hdf51.stage_sigs["capture"]
     if always_acquire:
         # This mode is "acquire always, capture on trigger"
         # Override the default to Continuous, always go
         self.stage_sigs['cam.acquire'] = 1
         self.stage_sigs['cam.image_mode'] = 2
         # Make sure we toggle capture for trigger
         self._acquisition_signal = self.hdf51.capture
     else:
         # This mode is "acquire on trigger, capture always"
         # Confirm default of Multiple, start off
         # Redundantly set these here for code clarity
         self.stage_sigs['cam.acquire'] = 0
         self.stage_sigs['cam.image_mode'] = 1
         # If we include capture in stage, it must be last
         self.hdf51.stage_sigs["capture"] = 1
         # Ensure we use the cam acquire as the trigger
         self._acquisition_signal = self.cam.acquire
Exemple #2
0
def test_hutch_name(monkeypatch):
    logger.debug('test_hutch_name')

    def fake_hutch_name(*args, **kwargs):
        return 'tst\n'

    monkeypatch.setattr(ext, 'call_script', fake_hutch_name)
    assert ext.get_hutch_name() == 'tst'
Exemple #3
0
 def setup_pmgr():
     try:
         from pmgr import pmgrAPI
     except ImportError:
         logger.error('Failed to import pmgr!')
         logger.debug('', exc_info=True)
         IMS._pm_init_error = True
     try:
         hutch = get_hutch_name()
     except Exception:
         logger.error('Could not determine hutch for pmgr!')
         logger.debug('', exc_info=True)
         IMS._pm_init_error = True
         return
     try:
         IMS._pm = pmgrAPI.pmgrAPI("ims_motor", hutch)
     except Exception:
         logger.error('Failed to create IMS pmgr object!')
         logger.debug('', exc_info=True)
         IMS._pm_init_error = True
         return
Exemple #4
0
    def screen(self, main: bool = False) -> None:
        """
        Open camViewer screen for camera.

        Parameters
        ----------
        main : bool, optional
            Set to True to bring up 'main' edm config screen.
            Defaults to False, which opens python viewer.
        """
        if not shutil.which('camViewer'):
            logger.error('no camViewer available')
            return

        arglist = [
            'camViewer', '-H',
            str(get_hutch_name()).lower(), '-c', self.name
        ]
        if main:
            arglist.append('-m')

        logger.info('starting camviewer')
        subprocess.run(arglist, check=False)
Exemple #5
0
def main():
    # Parse docopt variables
    args = docopt(__doc__)
    PVarguments = args["<PV>"]
    pattern = args["<pattern>"]
    if args["--zenity"] or args["-z"]:
        zenity = True
    else:
        zenity = False
    if args["--objtype"]:
        objType = args["--objtype"]
    else:
        objType = "ims_motor"
    if args["--hutch"]:
        hutch = args["--hutch"]
    else:
        hutch = get_hutch_name()
    if args["--parent"]:
        parent = args["--parent"]
    else:
        parent = hutch.upper()
    cfg = args["--cfg"]

    p = pmgrAPI(objType, hutch)

    if args["find"]:
        if args["--sensitive"] or args["-s"]:
            sensitive = True
        else:
            sensitive = False
        l = p.match_config(pattern, ci=not sensitive)
        if len(l) == 0:
            message(zenity, "error", 'No matches for "%s" found.' % pattern)
        else:
            message(zenity, "info",
                    'Possible matches for "%s":\n' % pattern + "\n".join(l))
        return 0

    # Parse the PV input into full PV names, exit if none input
    if len(PVarguments) > 0:
        motorPVs = parsePVArguments(PVarguments)
    else:
        message(zenity, "error", 'No PV input.  Try --help')

    # Sanity check arguments.
    if args['save'] and cfg and len(motorPVs) > 1:
        message(zenity, "error", 'Save with --cfg must be for a single motor.')
    if args["set"] and cfg is None:
        message(zenity, "error", 'Set must specify a configuration!')

    # Loop through each of the motorPVs
    msg = ""
    dialog = "info"
    for PV in motorPVs:
        # Print some motor info
        print("Motor PV:          {0}".format(PV))
        m_DESC = pv.get(PV + ".DESC")
        print("Motor description: {0}".format(m_DESC))

        if args["get"]:
            try:
                cfg = p.get_config(PV)
                msg += "Configuration of %s is %s.\n" % (PV, cfg)
            except Exception as e:
                msg += exc_to_str("get configuration of", PV, e)
                dialog = "error"
        if args["set"]:
            try:
                p.set_config(PV, cfgname=cfg)
                msg += "Configuration of %s successfully set to %s.\n" % (PV,
                                                                          cfg)
            except Exception as e:
                msg += exc_to_str("set configuration of", PV, e)
                dialog = "error"
        if args["apply"]:
            try:
                p.apply_config(PV, cfgname=cfg)
                msg += "Configuration of %s successfully applied.\n" % PV
            except Exception as e:
                msg += exc_to_str("apply configuration to", PV, e)
                dialog = "error"
        if args["diff"]:
            try:
                d = p.diff_config(PV)
                if len(d) == 0:
                    message(zenity, "info", "No differences for %s.\n" % PV)
                else:
                    m = "\n".join([
                        "    %s: actual=%s, configured=%s" %
                        (f, d[f][0], d[f][1]) for f in d.keys()
                    ])
                    message(zenity,
                            "info",
                            "Differences for %s:\n" % PV + m + "\n",
                            abort=False)
            except Exception as e:
                message(zenity,
                        "error",
                        exc_to_str("find differences of", PV, e),
                        abort=False)
        if args["save"]:
            try:
                p.save_config(PV, cfgname=cfg, overwrite=True, parent=parent)
                msg += "Configuration of %s successfully saved.\n" % PV
            except Exception as e:
                msg += exc_to_str("save configuration of", PV, e)
                dialog = "error"
    if args["diff"]:
        exit()
    message(zenity, dialog, msg)