コード例 #1
0
    def connectToSpec(self, specName, specVersion, timeout=None):
        SpecMotorA.connectToSpec(self, specName, specVersion)

        if not self.connection.isSpecConnected():
            w = SpecWaitObject.SpecWaitObject(self.connection)
            w.waitConnection(timeout)
            self._connected()
コード例 #2
0
    def connectToSpec(self, specName, specVersion, timeout=None):
        """Connect to a remote Spec

        Connect to Spec

        Arguments:
        specName -- name of the counter in Spec
        specVersion -- 'host:port' string representing a Spec server to connect to
        timeout -- optional timeout for connection (defaults to None)
        """
        self.specName = specName
        self.specVersion = specVersion

        self.connection = SpecConnectionsManager.SpecConnectionsManager(
        ).getConnection(specVersion)

        w = SpecWaitObject.SpecWaitObject(self.connection)
        w.waitConnection(timeout)

        c = self.connection.getChannel('var/%s' % self.specName)
        index = c.read()
        if index == 0:
            self.type = TIMER
        elif index == 1:
            self.type = MONITOR
        else:
            self.type = SCALER
コード例 #3
0
    def waitUpdate(self, waitValue = None, timeout = None):
        """Wait for the watched variable value to change

        Keyword arguments:
        waitValue -- wait for a specific variable value
        timeout -- optional timeout
        """
        if self.isConnected():
            w = SpecWaitObject.SpecWaitObject(self.connection)

            w.waitChannelUpdate(self.channelName, waitValue = waitValue, timeout = timeout)

            return w.value
コード例 #4
0
ファイル: Spec.py プロジェクト: zhangdongzhou/PX2_tools
    def connectToSpec(self, specVersion, timeout = None):
        """Connect to a remote Spec

        Mainly used for two-steps object creation.
        To be extended by derivated classes.

        Arguments:
        specVersion -- 'host:port' string representing the Spec version to connect to
        timeout -- optional connection timeout (defaults to None)
        """
        self.__specVersion = specVersion

        self.connection = SpecConnectionsManager.SpecConnectionsManager().getConnection(specVersion)

        w = SpecWaitObject.SpecWaitObject(self.connection)
        w.waitConnection(timeout)
コード例 #5
0
ファイル: SpecCounter.py プロジェクト: vallsv/specclient
    def connectToSpec(self, specName, specVersion, timeout=None):
        """Connect to a remote Spec

        Connect to Spec

        Arguments:
        specName -- name of the counter in Spec
        specVersion -- 'host:port' string representing a Spec server to connect to
        timeout -- optional timeout for connection (defaults to None)
        """
        SpecCounterA.connectToSpec(self, specName, specVersion)

        if not self.connection.isSpecConnected():
            w = SpecWaitObject.SpecWaitObject(self.connection)
            w.waitConnection(timeout)
            self._connected()
コード例 #6
0
    def move(self, absolutePosition):
        """Move the motor

        Block until the move is finished

        Arguments:
        absolutePosition -- position where to move the motor to
        """
        if self.connection is not None:
            c = self.connection.getChannel(self.chanNamePrefix % 'start_one')

            c.write(absolutePosition)

            w = SpecWaitObject.SpecWaitObject(self.connection)
            w.waitChannelUpdate(
                self.chanNamePrefix % 'move_done',
                waitValue=0)  #move_done is set to 0 when move has finished
コード例 #7
0
ファイル: SpecCommand.py プロジェクト: vallsv/specclient
    def executeCommand(self, command, wait=False, timeout=None):
        self._reply_arrived_event.clear()
        self.beginWait()

        with gevent.Timeout(timeout, SpecClientTimeoutError):
            waiter = SpecWaitObject.SpecWaitObject(self.connection)
            waiter.waitConnection()

            if self.connection.serverVersion < 3:
                id = self.connection.send_msg_cmd_with_return(command)
            else:
                if type(command) == types.StringType:
                    id = self.connection.send_msg_cmd_with_return(command)
                else:
                    id = self.connection.send_msg_func_with_return(command)

            t = gevent.spawn(wrap_errors(wait_end_of_spec_cmd), self)

            if wait:
                ret = t.get()
                if isinstance(ret, SpecClientError):
                    raise ret
                elif isinstance(ret, Exception):
                    self.abort()  #abort spec
                    raise
                else:
                    return ret
            else:
                t._get = t.get

                def special_get(self, *args, **kwargs):
                    ret = self._get(*args, **kwargs)
                    if isinstance(ret, SpecClientError):
                        raise ret
                    elif isinstance(ret, Exception):
                        self.abort()  #abort spec
                        raise
                    else:
                        return ret

                setattr(t, "get", types.MethodType(special_get, t))

                return t
コード例 #8
0
    def count(self, time):
        """Count up to a certain time or monitor count

        Arguments:
        time -- count time
        """
        if self.connection is not None:
            c1 = self.connection.getChannel('scaler/.all./count')
            c2 = self.connection.getChannel('scaler/%s/value' % self.specName)

            if self.type == MONITOR:
                time = -time

            c1.write(time)

            w = SpecWaitObject.SpecWaitObject(self.connection)
            w.waitChannelUpdate('scaler/.all./count', waitValue=0)

            return c2.read()
コード例 #9
0
    def connectToSpec(self, specName, specVersion, timeout=None):
        """Connect to a remote Spec

        Block until Spec is connected or timeout occurs

        Arguments:
        specName -- name of the motor in Spec
        specVersion -- 'host:port' string representing a Spec server to connect to
        timeout -- optional timeout for the connection (defaults to None)
        """
        self.specName = specName
        self.specVersion = specVersion
        self.chanNamePrefix = 'motor/%s/%%s' % specName

        self.connection = SpecConnectionsManager.SpecConnectionsManager(
        ).getConnection(specVersion)

        w = SpecWaitObject.SpecWaitObject(self.connection)
        w.waitConnection(timeout)
コード例 #10
0
    def connectToSpec(self, varName, specVersion, timeout = None, prefix=True):
        """Connect to a remote Spec

        Connect to Spec

        Arguments:
        varName -- the variable name in Spec
        specVersion -- 'host:port' string representing a Spec server to connect to
        timeout -- optional timeout (defaults to None)
        """
        if prefix:
          self.channelName = 'var/' + str(varName)
        else:
          self.channelName = str(varName)
        self.specVersion = specVersion

        self.connection = SpecConnectionsManager.SpecConnectionsManager().getConnection(specVersion)

        w = SpecWaitObject.SpecWaitObject(self.connection)
        w.waitConnection(timeout)
コード例 #11
0
ファイル: SpecCounter.py プロジェクト: vallsv/specclient
 def waitCount(self, timeout=None):
     w = SpecWaitObject.SpecWaitObject(self.connection)
     w.waitChannelUpdate(ALL_COUNT, waitValue=0)
     return self.getValue()
コード例 #12
0
        time -- count time
        """

        if self.connection is not None:
            try:
                _lock.acquire()
                c1 = self.connection.getChannel('scaler/.all./count')
                c2 = self.connection.getChannel('scaler/%s/value' %
                                                self.specName)

                if self.type == MONITOR:
                    time = -time

                c1.write(time)
            except Exception, e:
                print "counting lock acquisition failed"
                print repr(e)
            finally:
                _lock.release()
            w = SpecWaitObject.SpecWaitObject(self.connection)
            w.waitChannelUpdate('scaler/.all./count', waitValue=0)

            return c2.read()

    def getValue(self):
        """Return current counter value."""
        if self.connection is not None:
            c = self.connection.getChannel('scaler/%s/value' % self.specName)

            return c.read()