def _connectXml(self):
        '''
        \brief Connect over XML-RPC.
        '''
        
        # initialize the connector
        try:
            if isinstance(self.apiDef,HartMgrDefinition.HartMgrDefinition):
                self.connector = HartMgrConnector.HartMgrConnector()
            else:
                raise SystemError
        except NotImplementedError as err:
            self.guiLock.acquire()
            self.tipLabel.configure(text=str(err))
            self.guiLock.release()
            return
        print("connector initialized")

        # read connection params from GUI
        self.guiLock.acquire()
        connectParams = {
            'host':     self.xmlHostText.get(1.0,Tkinter.END).strip(),
            'port': int(self.xmlPortText.get(1.0,Tkinter.END).strip()),
        }
        self.guiLock.release()
        print("params accepted")
        print(connectParams)

        # connect
        try:
            self.connector.connect(connectParams)
        except ConnectionError as err:
            self.guiLock.acquire()
            self.xmlHostText.configure(bg=dustStyle.COLOR_ERROR)
            self.xmlPortText.configure(bg=dustStyle.COLOR_ERROR)
            self.tipLabel.configure(text=str(err))
            self.guiLock.release()
            return
        else:
            self.guiLock.acquire()
            self.xmlHostText.configure(bg=dustStyle.COLOR_NOERROR)
            self.xmlPortText.configure(bg=dustStyle.COLOR_NOERROR)
            self.tipLabel.configure(text="Connection successful.")
            self.guiLock.release()
        
        # hide other connectFrames
        self.guiLock.acquire()
        self.serialFrame.grid_forget()
        self.serialMuxFrame.grid_forget()
        self.guiLock.release()
        
        # update the button
        self.guiLock.acquire()
        self.xmlButton.configure(text='disconnect', command=self._disconnect)
        self.guiLock.release()
        
        # common connect routine
        self._connect()
 def _connect_xml(self):
     # initialize the connector
     try:
         if isinstance(self.apiDef, HartMgrDefinition.HartMgrDefinition):
             self.connector = HartMgrConnector.HartMgrConnector()
         else:
             raise SystemError
     except NotImplementedError as err:
         self.guiLock.acquire()
         # self.tipLabel.configure(text=str(err))
         self._is_not_used(err)
         self.guiLock.release()
         return
     print("connector initialized")
     print(self.connector)
     # read connection params from GUI
     self.guiLock.acquire()
     connect_params = {
         'host': self.XmlIpLineEdit.text().strip(),
         'port': int(self.XmlPortLineEdit.text().strip()),
     }
     self.guiLock.release()
     print("params accepted")
     print(connect_params)
     # connect
     try:
         self.connector.connect(connect_params)
     except ConnectionError as err:
         self.guiLock.acquire()
         print str(err)
         self.XmlIpLineEdit.setStyleSheet("background:" +
                                          PdStyle.COLOR_ERROR)
         self.XmlPortLineEdit.setStyleSheet("background:" +
                                            PdStyle.COLOR_ERROR)
         self.guiLock.release()
         return
     else:
         self.guiLock.acquire()
         self.XmlIpLineEdit.setStyleSheet("background:" +
                                          PdStyle.COLOR_NOERROR)
         self.XmlPortLineEdit.setStyleSheet("background:" +
                                            PdStyle.COLOR_NOERROR)
         self.guiLock.release()
     # update the button
     self.guiLock.acquire()
     self.XmlConnect.clicked.disconnect(self._connect_xml)
     self.XmlConnect.clicked.connect(self._disconnect_xml)
     self.XmlConnect.setText("断开")
     self.guiLock.release()
     # common connect routine
     self._connect()
Example #3
0
def callback_notimplemented(Tuple):
    return None, None


# Dictionary that relates notification type with callback function
NotificationParser = {
    'UserConnect': callback_userconnect,
    'MoteLive': callback_motelive,
    'data': callback_data
}
#============================ main ============================================

print '\n\n================== Step 1. Connecting to the manager =============='

print '\n=====\nCreating connector'
connector = HartMgrConnector.HartMgrConnector()
print 'done.'

print '\n=====\nConnecting to HART manager'
try:
    # Try to Connect
    connector.connect({})
except ConnectionError as err:
    # If a ConnectionError error is asserted, exit program
    print err
    sys.exit(1)
print 'done.'

print '\n\n================== Step 2. Getting information from the network ===='
# Logger function for AWS library
logger = logging.getLogger("AWSIoTPythonSDK.core")