Esempio n. 1
0
 def run(self):
     
     # connect to manager
     self.mgr = IpMgrConnectorSerial.IpMgrConnectorSerial()
     self.mgr.connect({'port': SERIALPORT_MGR})
     
     # connect to tag
     self.tag = IpMoteConnector.IpMoteConnector()
     self.tag.connect({'port': SERIALPORT_TAG})
     
     for networksize in range(5,46,5):
         self.runExperimentForSize(networksize)
Esempio n. 2
0
    def _init_mote(self):
        print 'MoteClock from SyncPi'
        self.moteconnector = IpMoteConnector.IpMoteConnector()

        # self.serialport = raw_input("Enter the serial API port of SmartMesh IP Mote (e.g. COM15): ")
        # On linux the port is probably this one below, so just comment the line above and uncomment the one below
        self.serialport = "/dev/serial/by-id/usb-Dust_Networks_Dust_Huron-if03-port0"

        print "- connect to the mote's serial port: {}".format(self.serialport)

        self.moteconnector.connect({'port': self.serialport})

        while True:
            res = self.moteconnector.dn_getParameter_moteStatus()
            print "   current mote state: {0}".format(res.state)

            if res.state == 1:
                self.moteconnector.dn_join()
            elif res.state == 5:
                break
            time.sleep(1)
Esempio n. 3
0
                                     ['getParameter', 'moteStatus'],
                                     'state').optionDescs

print '\n\n================== Step 2. Connecting to a device ================='

connect = raw_input('\nDo you want to connect to a device? [y/n] ')

if connect.strip() != 'y':
    raw_input('\nScript ended. Press Enter to exit.')
    sys.exit()

serialPort = raw_input(
    '\nEnter the serial port of the IP mote\'s API (e.g. COM30) ')

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

print '\n=====\nConnecting to IP mote'
try:
    connector.connect({
        'port': serialPort,
    })
except ConnectionError as err:
    print err
    raw_input('\nScript ended. Press Enter to exit.')
print 'done.'

print '\n\n================== Step 3. Getting information from the device ===='

try:
Esempio n. 4
0
    def run(self):

        while self.goOn:

            try:
                # create a connector
                self.connector = IpMoteConnector.IpMoteConnector()

                # connect to the manager
                print 'connecting to {0}...'.format(self.port),
                self.connector.connect({
                    'port': self.port,
                })
                print 'done.'

                # set the current channel to default
                chanIdx = 0

                # loop to the infinite and beyond
                while self.goOn:

                    # channel
                    mask = 0x1 << chanIdx * 4

                    # listen for packets
                    mask_hex = self._num_to_list(mask, 2)
                    self.connector.dn_testRadioRx(
                        channelMask=mask_hex,  # channel
                        time=DFLT_DURATION,  # listening time
                        stationId=self.stationId  # stationId
                    )
                    radioRxDone = False

                    while self.goOn:
                        time.sleep(1)

                        # get last statistics
                        try:
                            testRadioRxStats = self.connector.dn_getParameter_testRadioRxStats(
                            )
                        except APIError:
                            continue

                        break

                    # save rxOk
                    self.rxOk[chanIdx] = testRadioRxStats.rxOk

                    # print rxOk
                    output = []
                    output += ['']
                    sum = 0
                    num = 0
                    for i in range(0, 4):
                        channel = i * 4
                        if i == chanIdx:
                            star = "*"
                        else:
                            star = " "
                        if self.rxOk[i] == None:
                            bar = ''
                        else:
                            num += 1
                            sum += self.rxOk[i]
                            bar = "{0}|".format('-' * (self.rxOk[i] / 2), )
                        output += [
                            "{0} channel={1}\t{2} {3}".format(
                                star, channel, bar, self.rxOk[i])
                        ]
                    output += [
                        "Total: {0} packets\t({1:.2f}%)".format(
                            sum,
                            float(sum) / float(num))
                    ]
                    output = '\n'.join(output)
                    print output

                    # switch to next channel
                    chanIdx = (chanIdx + 1) % 4

            except Exception as err:
                print err
                try:
                    self.connector.disconnect()
                except:
                    pass
                time.sleep(1)
# global
AppUtils.configureLogging()

#============================ defines =========================================

DEFAULT_MGRSERIALPORT = 'COM15'
DEFAULT_MOTESERIALPORT = 'COM19'

#============================ helper functions ================================

#============================ main ============================================

try:
    manager = IpMgrConnectorSerial.IpMgrConnectorSerial()
    mote = IpMoteConnector.IpMoteConnector()

    print 'ACL Commissioning (c) Dust Networks'
    print 'SmartMesh SDK {0}\n'.format('.'.join(
        [str(b) for b in sdk_version.VERSION]))

    print '==== Connect to manager'
    serialport = raw_input(
        "Serial port of SmartMesh IP Manager (e.g. {0}): ".format(
            DEFAULT_MGRSERIALPORT))
    serialport = serialport.strip()
    if not serialport:
        serialport = DEFAULT_MGRSERIALPORT
    manager.connect({'port': serialport})
    print 'Connected to manager at {0}.\n'.format(serialport)
 def _connectSerial(self):
     '''
     \brief Connect through the serial port.
     '''
    
     # initialize the connector
     try:
         if   isinstance(self.apiDef,IpMgrDefinition.IpMgrDefinition):
             self.connector = IpMgrConnectorSerial.IpMgrConnectorSerial()
         elif isinstance(self.apiDef,IpMoteDefinition.IpMoteDefinition):
             self.connector = IpMoteConnector.IpMoteConnector()
         elif isinstance(self.apiDef,HartMoteDefinition.HartMoteDefinition):
             self.connector = HartMoteConnector.HartMoteConnector()
         else:
             raise SystemError
     except NotImplementedError as err:
         self.guiLock.acquire()
         self.tipLabel.configure(text=str(err))
         self.guiLock.release()
         return
     
     # read connection params from GUI
     self.guiLock.acquire()
     connectParams = {
         'port': self.serialPortText.get(1.0,Tkinter.END).strip(),
     }
     self.guiLock.release()
     
     # connect to the serial port
     try:
         self.connector.connect(connectParams)
     except ConnectionError as err:
         self.guiLock.acquire()
         self.serialPortText.configure(bg=dustStyle.COLOR_ERROR)
         self.tipLabel.configure(text=str(err))
         self.guiLock.release()
         return
         
     # if you get here, the connector could connect, i.e. the COM port is available
     
     # make sure that the device attached to the serial port is really the mote we expect
     if   isinstance(self.apiDef,IpMgrDefinition.IpMgrDefinition):
         # nothing to do, since connecting to a manager includes a handshake
         pass
     
     elif isinstance(self.apiDef,IpMoteDefinition.IpMoteDefinition):
         try:
             res = self.connector.dn_getParameter_moteInfo()
         except (ConnectionError,CommandError) as err:
             
             # disconnect the connector
             self.connector.disconnect()
             
             # print error text
             output  = []
             output += ["Could open the COM port, but issuing dn_getParameter_moteInfo() failed."]
             output += ["Exact error received: {0}".format(err)]
             output += ["Please verify that the device connected to {0} is a SmartMesh IP mote.".format(connectParams['port'])]
             output += ["Please verify that the SmartMesh IP mote is configured in slave mode."]
             output  = '\n'.join(output)
             self.guiLock.acquire()
             self.serialPortText.configure(bg=dustStyle.COLOR_WARNING_NOTWORKING)
             self.tipLabel.configure(text=output)
             self.guiLock.release()
             return
         
     elif isinstance(self.apiDef,HartMoteDefinition.HartMoteDefinition):
         
         try:
             res = self.connector.dn_getParameter_moteInfo()
         except (ConnectionError,CommandError) as err:
             
             # disconnect the connector
             self.connector.disconnect()
             
             # print error text
             output  = []
             output += ["Could open the COM port, but issuing dn_getParameter_moteInfo() failed."]
             output += ["Exact error received: {0}".format(err)]
             output += ["Please verify that the device connected to {0} is a SmartMesh WirelessHART mote.".format(connectParams['port'])]
             output += ["Please verify that the SmartMesh WirelessHART mote is configured in slave mode."]
             output  = '\n'.join(output)
             self.guiLock.acquire()
             self.serialPortText.configure(bg=dustStyle.COLOR_WARNING_NOTWORKING)
             self.tipLabel.configure(text=output)
             self.guiLock.release()
             return
     else:
         raise SystemError
     
     # if you get here, the connection has succeeded
     self.guiLock.acquire()
     self.serialPortText.configure(bg=dustStyle.COLOR_NOERROR)
     self.tipLabel.configure(text="Connection successful.")
     self.guiLock.release()
     
     # hide other connectFrames
     self.guiLock.acquire()
     self.serialMuxFrame.grid_forget()
     self.xmlFrame.grid_forget()
     self.guiLock.release()
     
     # update the button
     self.guiLock.acquire()
     self.serialButton.configure(text='disconnect', command=self._disconnect)
     self.guiLock.release()
     
     # common connect routing
     self._connect()