def connectToSpec(self, varName, specVersion, dispatchMode = UPDATEVALUE, prefix=True): """Connect to a remote Spec Connect to Spec and register channel for monitoring variable Arguments: varName -- name of the variable specVersion -- 'host:port' string representing a Spec server to connect to """ self.varName = varName self.specVersion = specVersion if prefix: self.channelName = 'var/%s' % varName else: self.channelName = varName if isinstance(specVersion,str): self.connection = SpecConnectionsManager.SpecConnectionsManager().getConnection(specVersion) else: self.connection = specVersion self.connection.connect('connected', self._connected) self.connection.connect('disconnected', self._disconnected) self.dispatchMode = dispatchMode if self.connection.isSpecConnected(): self._connected()
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
def connectToSpec(self, specVersion, timeout=None): 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()
def waitFunc(timeout): """Waiting function Arguments: timeout -- waiting time in milliseconds """ try: P = getattr(SpecConnectionsManager.SpecConnectionsManager(), "poll") except AttributeError: time.sleep(timeout / 1000.0) SpecEventsDispatcher.dispatch() else: P(timeout / 1000.0)
def waitConnection(connection, timeout=None): """Wait for a connection to Spec to be established Arguments: connection -- a 'host:port' string timeout -- optional timeout (defaults to None) """ if type(connection) in (types.UnicodeType, types.StringType): from SpecClient.SpecConnectionsManager import SpecConnectionsManager connection = SpecConnectionsManager().getConnection(str(connection)) w = SpecWaitObject(connection) w.waitConnection(timeout=timeout)
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)
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)
def waitReply(connection, command, argsTuple, timeout=None): """Wait for a reply from a remote Spec server Arguments: connection -- a 'host:port' string command -- command to execute argsTuple -- tuple of arguments for the command timeout -- optional timeout (defaults to None) """ if type(connection) in (types.UnicodeType, types.StringType): connection = str(connection) from SpecClient.SpecConnectionsManager import SpecConnectionsManager connection = SpecConnectionsManager().getConnection(connection) waitConnection(connection, timeout=timeout) w = SpecWaitObject(connection) w.waitReply(command, argsTuple, timeout=timeout) return w.value
def waitChannelUpdate(chanName, connection, waitValue=None, timeout=None): """Wait for a channel to be updated Arguments: chanName -- channel name (e.g 'var/toto') connection -- a 'host:port' string waitValue -- value to wait (defaults to None) timeout -- optional timeout (defaults to None) """ if type(connection) in (types.UnicodeType, types.StringType): connection = str(connection) from SpecClient.SpecConnectionsManager import SpecConnectionsManager connection = SpecConnectionsManager().getConnection(connection) waitConnection(connection, timeout=timeout) w = SpecWaitObject(connection) w.waitChannelUpdate(chanName, waitValue=waitValue, timeout=timeout) return w.value
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)
def connectToSpec(self, specName, specVersion): """Connect to a remote Spec Connect to Spec and register channels of interest for the specified motor Arguments: specName -- name of the motor in Spec specVersion -- 'host:port' string representing a Spec server to connect to """ self.specName = specName self.specVersion = specVersion self.chanNamePrefix = 'motor/%s/%%s' % specName self.connection = SpecConnectionsManager.SpecConnectionsManager( ).getConnection(specVersion) SpecEventsDispatcher.connect(self.connection, 'connected', self.__connected) SpecEventsDispatcher.connect(self.connection, 'disconnected', self.__disconnected) if self.connection.isSpecConnected(): self.__connected()
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.chanNamePrefix = 'scaler/%s/%%s' % specName self.connection = SpecConnectionsManager.SpecConnectionsManager( ).getConnection(specVersion) SpecEventsDispatcher.connect(self.connection, 'connected', self._connected) SpecEventsDispatcher.connect(self.connection, 'disconnected', self._disconnected) if self.connection.isSpecConnected(): self._connected()
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()
def connectToSpec(self, specVersion): self.connection = SpecConnectionsManager.SpecConnectionsManager( ).getConnection(specVersion) self.specVersion = specVersion SpecWaitObject.waitConnection(self.connection, self.__timeout)