Exemplo n.º 1
0
    def __init__(self,
                 *,
                 name,
                 variable=None,
                 dependencies=None,
                 linkedSet=None,
                 linkedGet=None,
                 **kwargs):  # Args passed to BaseVariable

        # Set and get functions
        self._linkedGet = linkedGet
        self._linkedSet = linkedSet

        if variable is not None:
            # If directly linked to a variable, use it's value and set by defualt
            # for linkedGet and linkedSet unless overridden
            self._linkedGet = linkedGet if linkedGet else variable.get
            self._linkedSet = linkedSet if linkedSet else variable.set

            # Search the kwargs for overridden properties, otherwise the properties from the linked variable will be used
            args = ['disp', 'enum', 'units', 'minimum', 'maximum']
            for arg in args:
                if arg not in kwargs:
                    kwargs[arg] = getattr(variable, arg)

        # Why not inhertit mode from link variable?
        if not self._linkedSet:
            kwargs['mode'] = 'RO'
        if not self._linkedGet:
            kwargs['mode'] = 'WO'

        # Wrap linked get and set functions
        self._linkedGetWrap = pr.functionWrapper(
            function=self._linkedGet,
            callArgs=['dev', 'var', 'read', 'index', 'check'])
        self._linkedSetWrap = pr.functionWrapper(function=self._linkedSet,
                                                 callArgs=[
                                                     'dev', 'var', 'value',
                                                     'write', 'index',
                                                     'verify', 'check'
                                                 ])

        # Call super constructor
        BaseVariable.__init__(self, name=name, **kwargs)

        # Dependency tracking
        if variable is not None:
            # Add the directly linked variable as a dependency
            self.addDependency(variable)

        if dependencies is not None:
            for d in dependencies:
                self.addDependency(d)
Exemplo n.º 2
0
    def __init__(self,
                 *,
                 name=None,
                 description="",
                 value=0,
                 retValue=None,
                 enum=None,
                 hidden=False,
                 groups=None,
                 minimum=None,
                 maximum=None,
                 function=None,
                 background=False,
                 guiGroup=None):

        pr.BaseVariable.__init__(self,
                                 name=name,
                                 description=description,
                                 mode='WO',
                                 value=value,
                                 enum=enum,
                                 hidden=hidden,
                                 groups=groups,
                                 minimum=minimum,
                                 maximum=maximum,
                                 bulkOpEn=False,
                                 guiGroup=guiGroup)

        self._function = function
        self._functionWrap = pr.functionWrapper(
            function=self._function, callArgs=['root', 'dev', 'cmd', 'arg'])

        self._thread = None
        self._lock = threading.Lock()
        self._background = background

        if self._background:
            self._log.error(
                'Background commands are deprecated. Please use a Process device instead.'
            )

        if retValue is None:
            self._retTypeStr = None
        elif isinstance(retValue, list):
            self._retTypeStr = f'List[{retValue[0].__class__.__name__}]'
        else:
            self._retTypeStr = retValue.__class__.__name__

        # args flag
        try:
            self._arg = 'arg' in inspect.getfullargspec(self._function).args

        # C++ functions
        except Exception:
            self._arg = False
Exemplo n.º 3
0
    def __init__(self, *, variable, localSet, localGet, value):
        self._path = variable.path
        self._mode = variable.mode
        self._device = variable.parent
        self._localSet = localSet
        self._localGet = localGet
        self._variable = variable
        self._variables = [variable]  # Used by poller
        self._value = value
        self._lock = threading.RLock()
        self._doUpdate = False
        self._enable = True

        # Setup logging
        self._log = pr.logInit(cls=self, name=self._path)

        # Wrap local functions
        self._localSetWrap = pr.functionWrapper(
            function=self._localSet,
            callArgs=['dev', 'var', 'value', 'changed'])
        self._localGetWrap = pr.functionWrapper(function=self._localGet,
                                                callArgs=['dev', 'var'])
Exemplo n.º 4
0
 def replaceFunction(self, function):
     self._function = function
     self._functionWrap = pr.functionWrapper(
         function=self._function, callArgs=['root', 'dev', 'cmd', 'arg'])
Exemplo n.º 5
0
    def __init__(self,
                 *,
                 argVariable=None,
                 returnVariable=None,
                 function=None,
                 **kwargs):

        pr.Device.__init__(self, **kwargs)

        self._lock = threading.Lock()
        self._thread = None
        self._runEn = False
        self._argVar = argVariable
        self._retVar = returnVariable
        self._function = function

        self._functionWrap = pr.functionWrapper(
            function=self._function, callArgs=['root', 'dev', 'arg'])

        self.add(
            pr.LocalCommand(name='Start',
                            function=self._startProcess,
                            description='Start process.'))

        self.add(
            pr.LocalCommand(name='Stop',
                            function=self._stopProcess,
                            description='Stop process.'))

        self.add(
            pr.LocalVariable(name='Running',
                             mode='RO',
                             value=False,
                             pollInterval=1.0,
                             description='Operation is running.'))

        self.add(
            pr.LocalVariable(name='Progress',
                             mode='RO',
                             units='Pct',
                             value=0.0,
                             disp='{:1.2f}',
                             minimum=0.0,
                             maximum=1.0,
                             pollInterval=1.0,
                             description='Percent complete: 0.0 - 1.0.'))

        self.add(
            pr.LocalVariable(
                name='Message',
                mode='RO',
                value='',
                pollInterval=1.0,
                description=
                'Process status message. Prefix with Error: if an error occurred.'
            ))

        # Add arg variable if not already added
        if self._argVar is not None and self._argVar not in self:
            self.add(self._argVar)

        # Add return variable if not already added
        if self._retVar is not None and self._retVar not in self:
            self.add(self._retVar)