def connect(self):
        if self.__connected:
            return
        try:
            self.invalidHardwareObjects = set()
            self.hardwareObjects = weakref.WeakValueDictionary()

            if isinstance(self.serverAddress, string_types):
                mngr = SpecConnectionsManager.SpecConnectionsManager()
                self.server = mngr.getConnection(self.serverAddress)

                with gevent.Timeout(3):
                    while not self.server.isSpecConnected():
                        time.sleep(0.5)

                # in case of update of a Hardware Object, we discard it => bricks will
                # receive a signal and can reload it
                self.server.registerChannel(
                    "update",
                    self.discardHardwareObject,
                    dispatchMode=SpecEventsDispatcher.FIREEVENT,
                )
            else:
                self.server = None
        finally:
            self.__connected = True
Esempio n. 2
0
    def getConnection(self, connectionName):
        """Return the Connection object for a Spec connection, given its name

        Parameters :
          connectionName -- a Spec version name ('host:port' string)

        Return :
          the corresponding SpecConnection object
        """
        connectionsManager = SpecConnectionsManager.SpecConnectionsManager()

        return connectionsManager.getConnection(connectionName)
Esempio n. 3
0
    def setSpecVersion(self, specVersion):
        scanCmd = self.getCommandObject('start')
        scanCmd.setSpecVersion(specVersion)
        
        if specVersion is not None:
            self.specConnection = SpecConnectionsManager.SpecConnectionsManager().getConnection(specVersion)

            if self.specConnection is not None:
                SpecEventsDispatcher.connect(self.specConnection, 'connected', self.connected)
                SpecEventsDispatcher.connect(self.specConnection, 'disconnected', self.disconnected)
                
                if self.specConnection.isSpecConnected():
                    self.connected()
Esempio n. 4
0
    def setSpecVersion(self, specVersion):
        scanCmd = self.get_command_object("start")
        scanCmd.setSpecVersion(specVersion)

        if specVersion is not None:
            self.specConnection = SpecConnectionsManager.SpecConnectionsManager(
            ).get_connection(specVersion)

            if self.specConnection is not None:
                SpecEventsDispatcher.connect(self.specConnection, "connected",
                                             self.connected)
                SpecEventsDispatcher.connect(self.specConnection,
                                             "disconnected", self.disconnected)

                if self.specConnection.isSpecConnected():
                    self.connected()
Esempio n. 5
0
    def connect(self):
        self.invalidHardwareObjects = set()
        self.hardwareObjects = weakref.WeakValueDictionary()

        if type(self.serverAddress)==bytes:
            mngr = SpecConnectionsManager.SpecConnectionsManager() 

            self.server = mngr.getConnection(self.serverAddress)
      
            with gevent.Timeout(3): 
                while not self.server.isSpecConnected():
                    time.sleep(0.5) 
            #SpecWaitObject.waitConnection(self.server, timeout = 3)
   
            # in case of update of a Hardware Object, we discard it => bricks will receive a signal and can reload it
            self.server.registerChannel("update", self.discardHardwareObject, dispatchMode=SpecEventsDispatcher.FIREEVENT)
        else:
            self.server = None
Esempio n. 6
0
 def init(self):
     self.allMotors = None
     self.motorListMacro = None
     self.gettingMotors = None
     try:
         self.specConnection = SpecConnectionsManager.SpecConnectionsManager(
         ).getConnection(self.specversion)
     except AttributeError:
         self.specConnection = None
         logging.getLogger("HWR").error(
             'MotorList: you must specify a spec version')
     else:
         SpecEventsDispatcher.connect(self.specConnection, 'connected',
                                      self.sConnected)
         SpecEventsDispatcher.connect(self.specConnection, 'disconnected',
                                      self.sDisconnected)
         if self.isConnected():
             self.sConnected()