Example #1
0
    def connectToSpec(self, specVersion, timeout):
        SpecCommandA.connectToSpec(self, specVersion, timeout)

        if not self.connection.isSpecConnected():
            with gevent.Timeout(timeout, SpecClientTimeoutError):
                SpecWaitObject.waitConnection(self.connection, timeout)
            self._connected()
Example #2
0
    def connectToSpec(self, specVersion, timeout):
        SpecCommandA.connectToSpec(self, specVersion, timeout)

        if not self.connection.isSpecConnected():
            with gevent.Timeout(timeout, SpecClientTimeoutError):
                SpecWaitObject.waitConnection(self.connection, timeout)
            self._connected()
Example #3
0
    def connectToSpec(self, specVersion, timeout=200):
        if self.connection is not None:
            SpecEventsDispatcher.disconnect(self.connection, 'connected', self.connected)
            SpecEventsDispatcher.disconnect(self.connection, 'disconnected', self.disconnected)

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

        SpecEventsDispatcher.connect(self.connection, 'connected', self.connected)
        cb = self.__callbacks.get("connected")
        if cb is not None:
          cb = cb()
          SpecEventsDispatcher.connect(self.connection, 'connected', cb)
        SpecEventsDispatcher.connect(self.connection, 'disconnected', self.disconnected)
        cb = self.__callbacks.get("disconnected")
        if cb is not None:
          cb = cb()
          SpecEventsDispatcher.connect(self.connection, 'disconnected', cb)
        self.connection.registerChannel("status/ready", self.statusChanged)
        cb = self.__callbacks.get("statusChanged")
        if cb is not None:
          cb = cb()
          SpecEventsDispatcher.connect(self.connection, 'statusChanged', cb)

        if self.connection.isSpecConnected():
            self.connected()
        else:
            try:
              SpecWaitObject.waitConnection(self.connection, timeout)
            except SpecClientTimeoutError:
              pass
            SpecEventsDispatcher.dispatch()
Example #4
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
Example #5
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()
Example #6
0
    def executeCommand(self, command):
        if self.connection.serverVersion < 3:
            connectionCommand = 'send_msg_cmd_with_return'
        else:
            if type(command) == types.StringType:
                connectionCommand = 'send_msg_cmd_with_return'
            else:
                connectionCommand = 'send_msg_func_with_return'

        return SpecWaitObject.waitReply(self.connection, connectionCommand, (command, ), self.__timeout)
Example #7
0
    def executeCommand(self, command):
        if self.connection.serverVersion < 3:
            connectionCommand = 'send_msg_cmd_with_return'
        else:
            if type(command) == types.StringType:
                connectionCommand = 'send_msg_cmd_with_return'
            else:
                connectionCommand = 'send_msg_func_with_return'

        return SpecWaitObject.waitReply(self.connection, connectionCommand,
                                        (command, ), self.__timeout)
Example #8
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
Example #9
0
    def connectToSpec(self, specVersion, timeout=200):
        if self.connection is not None:
            SpecEventsDispatcher.disconnect(self.connection, 'connected',
                                            self._connected)
            SpecEventsDispatcher.disconnect(self.connection, 'disconnected',
                                            self._disconnected)

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

        SpecEventsDispatcher.connect(self.connection, 'connected',
                                     self._connected)
        SpecEventsDispatcher.connect(self.connection, 'disconnected',
                                     self._disconnected)

        if self.connection.isSpecConnected():
            self._connected()
        else:
            try:
                SpecWaitObject.waitConnection(self.connection, timeout)
            except SpecClientTimeoutError:
                pass
            SpecEventsDispatcher.dispatch()
Example #10
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)
        """
        SpecCounterA.connectToSpec(self, specName, specVersion)

        if not self.connection.isSpecConnected():
            w = SpecWaitObject.SpecWaitObject(self.connection)
            w.waitConnection(timeout)
            self._connected()
Example #11
0
    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)
Example #12
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
Example #13
0
    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
Example #14
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()
Example #15
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)
Example #16
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)
Example #17
0
    def read(self, timeout=3, force_read=False):
        """Read the channel value

        If channel is registered, just return the internal value,
        else obtain the channel value and return it.
        """
        if not force_read and self.registered:
            if self.value is not None:
              #we check 'value is not None' because the
              #'registered' flag could be set, but before
              #the message with the channel value arrived 
              return self.value

        connection = self.connection()

        if connection is not None:
            # make sure spec is connected, we give a short timeout
            # because it is supposed to be the case already
            value = SpecWaitObject.waitReply(connection, 'send_msg_chan_read', (self.spec_chan_name, ), timeout=timeout)
            if value is None:
                raise RuntimeError("could not read channel %r" % self.spec_chan_name)
            self.update(value)
            return self.value
Example #18
0
    def read(self, timeout=3, force_read=False):
        """Read the channel value

        If channel is registered, just return the internal value,
        else obtain the channel value and return it.
        """
        if not force_read and self.registered:
            if self.value is not None:
              #we check 'value is not None' because the
              #'registered' flag could be set, but before
              #the message with the channel value arrived 
              return self.value

        connection = self.connection()

        if connection is not None:
            # make sure spec is connected, we give a short timeout
            # because it is supposed to be the case already
            value = SpecWaitObject.waitReply(connection, 'send_msg_chan_read', (self.spec_chan_name, ), timeout=timeout)
            if value is None:
                raise RuntimeError("could not read channel %r" % self.spec_chan_name)
            self.update(value)
            return self.value
        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()
Example #20
0
 def waitCount(self, timeout=None):
     w = SpecWaitObject.SpecWaitObject(self.connection)
     w.waitChannelUpdate(ALL_COUNT, waitValue=0)
     return self.getValue()
Example #21
0
    def connectToSpec(self, specVersion):
        self.connection = SpecConnectionsManager.SpecConnectionsManager(
        ).getConnection(specVersion)
        self.specVersion = specVersion

        SpecWaitObject.waitConnection(self.connection, self.__timeout)
Example #22
0
    def connectToSpec(self, specVersion):
        self.connection = SpecConnectionsManager.SpecConnectionsManager().getConnection(specVersion)
        self.specVersion = specVersion

        SpecWaitObject.waitConnection(self.connection, self.__timeout)