def talkToXBee(self): # allow direct interaction with XBee (Arduino code needs modification)
   if raw_input("Configure this (Arduino's) XBee before mapping? [y/N]: ").lower() == 'y':
     while True:
       inputStr = raw_input("Enter XBee command: ")
       sendStr = inputStr if (inputStr == "+++" or inputStr == '') else inputStr + '\x0D'
       self.ser.write(sendStr)
       tstart = time()
       while time() < tstart + 1: # give XBee 1 sec to respond
         if self.ser.inWaiting(): print(self.ser.read())
       if inputStr.lower() == "atcn": # we've told the XBee to exit command mode, so we should, too...
         self.ser.write('q') # tells Arduino to stop talking to XBee (shouldn't affect computer XBee...)
         break
     sys.exit("Please restart XBee and then re-run this code.") # XBee has to power cycle for change to take effect
Beispiel #2
0
    def connectToPort(self):
        # first select a port to use
        portList = sorted([
            port[0] for port in list_ports.comports()
            if 'USB' in port[0] or 'COM' in port[0]
        ])
        if not portList:  # list empty
            sys.exit(
                "Check your COM ports for connected devices and compatible drivers."
            )
        elif len(
                portList) == 1:  # if there's only one device connected, use it
            portName = portList[0]
        else:  # query user for which port to use
            print("Available COM ports:")
            print(portList)
            portRequested = raw_input(
                "Please select a port number [%s]: " %
                ', '.join([str(el[-1]) for el in portList]))
            portName = (
                portList[0][0:-1] +
                portRequested) if portRequested is not "" else portList[0]

        # then try to connect to it
        try:
            self.ser = Serial(portName, baudrate=XBEE_BAUD)
        except SerialException:
            sys.exit("Invalid port.")
        else:
            sleep(1)  # give time to connect to serial port
            print("Successfully connected to: %s" % portName)
Beispiel #3
0
 def talkToXBee(
     self
 ):  # allow direct interaction with XBee (Arduino code needs modification)
     if raw_input("Configure this (Arduino's) XBee before mapping? [y/N]: "
                  ).lower() == 'y':
         while True:
             inputStr = raw_input("Enter XBee command: ")
             sendStr = inputStr if (
                 inputStr == "+++" or inputStr == '') else inputStr + '\x0D'
             self.ser.write(sendStr)
             tstart = time()
             while time() < tstart + 1:  # give XBee 1 sec to respond
                 if self.ser.inWaiting(): print(self.ser.read())
             if inputStr.lower(
             ) == "atcn":  # we've told the XBee to exit command mode, so we should, too...
                 self.ser.write(
                     'q'
                 )  # tells Arduino to stop talking to XBee (shouldn't affect computer XBee...)
                 break
         sys.exit("Please restart XBee and then re-run this code."
                  )  # XBee has to power cycle for change to take effect
  def connectToPort(self):
    # first select a port to use
    portList = sorted([port[0] for port in list_ports.comports() if 'USB' in port[0] or 'COM' in port[0]])
    if not portList: # list empty
      sys.exit("Check your COM ports for connected devices and compatible drivers.")
    elif len(portList) == 1: # if there's only one device connected, use it
      portName = portList[0]
    else: # query user for which port to use
      print("Available COM ports:")
      print(portList)
      portRequested = raw_input("Please select a port number [%s]: " % ', '.join([str(el[-1]) for el in portList]))
      portName = (portList[0][0:-1] + portRequested) if portRequested is not "" else portList[0]

    # then try to connect to it
    try:
      self.ser = Serial(portName, baudrate=XBEE_BAUD)
    except SerialException:
      sys.exit("Invalid port.")
    else:
      sleep(1) # give time to connect to serial port
      print("Successfully connected to: %s" % portName)