示例#1
0
    def do_term(self, p):
        """Assuming you have setup XBee modems to communicate in a point-to-point mode, the interpretor will establish a serial terminal interface to the XBee.  Data arriving at XBee will be printed and characters entered at the keyboard will be sent via the XBee."""
        if not self.serial.isOpen():
            print "You must set a serial port first."
        else:
            print "Entering \"term\" mode (Ctrl-C to abort)..."
            try:
                #self.serial.timeout = 0
                while True:
                    # read a line from XBee and convert it from b'xxx\r\n' to xxx
                    #                    switchColor(TERM_OUTPUT_TEXT)
                    line = self.serial.readline().decode('utf-8')[:-2]
                    if line:
                        print line
                    # read data from the keyboard and send via the XBee modem
#                    switchColor(TERM_INPUT_TEXT)
                    line = sys.stdin.readline()
                    self.serial.writelines(line)
                    self.serial.flush()
                    """
                    output = ''
                    while self.serial.inWaiting():
                        output += self.serial.read()
                    if output == '':
                        print 'XBee timed out, so reissue "+++". (Or maybe XBee doesn\'t understand "%s".)' % p
                    else:
                        print output.replace('\r', '\n').rstrip()
                    """
            except KeyboardInterrupt:
                printc("\n*** Ctrl-C keyboard interrupt ***", ERROR_TEXT)
示例#2
0
    def do_term(self, p):
        """Assuming you have setup XBee modems to communicate in a point-to-point mode, the interpretor will establish a serial terminal interface to the XBee.  Data arriving at XBee will be printed and characters entered at the keyboard will be sent via the XBee."""
        if not self.serial.isOpen():
            print "You must set a serial port first."
        else:
            print "Entering \"term\" mode (Ctrl-C to abort)..."
            try:
                #self.serial.timeout = 0
                while True:
                    # read a line from XBee and convert it from b'xxx\r\n' to xxx
#                    switchColor(TERM_OUTPUT_TEXT)
                    line = self.serial.readline().decode('utf-8')[:-2]
                    if line:
                        print line
                    # read data from the keyboard and send via the XBee modem
#                    switchColor(TERM_INPUT_TEXT)
                    line = sys.stdin.readline()
                    self.serial.writelines(line)
                    self.serial.flush()
                    """
                    output = ''
                    while self.serial.inWaiting():
                        output += self.serial.read()
                    if output == '':
                        print 'XBee timed out, so reissue "+++". (Or maybe XBee doesn\'t understand "%s".)' % p
                    else:
                        print output.replace('\r', '\n').rstrip()
                    """
            except KeyboardInterrupt:
                printc("\n*** Ctrl-C keyboard interrupt ***", ERROR_TEXT)
示例#3
0
    def do_watch(self, p):
        """Assuming you have set the XBee to data mode, wait for the arrival of a XBee data packet, print it when it arrives, and wait for the next packet."""
        if not self.serial.isOpen():
            print "You must set a serial port first."
        else:
            print "Entering \"watch\" mode (Ctrl-C to abort)..."
            ser = serial.Serial(self.serial.port, self.serial.baudrate)     # Open XBee serial port
            xbee = XBee(ser)                        # Create XBee object to manage packets
            dispatch = Dispatch(xbee=xbee)          # Start the dispatcher that will call packet handlers
#            switchColor(WATCH_OUTPUT_TEXT)
            try:
                dispatch.run()    # run() will loop infinitely while waiting for and processing packets which arrive.
            except KeyboardInterrupt:
                printc("\n*** Ctrl-C keyboard interrupt ***", ERROR_TEXT)
            ser.close()
            switchColor(WATCH_OUTPUT_TEXT)
示例#4
0
 def do_watch(self, p):
     """Assuming you have set the XBee to data mode, wait for the arrival of a XBee data packet, print it when it arrives, and wait for the next packet."""
     if not self.serial.isOpen():
         print "You must set a serial port first."
     else:
         print "Entering \"watch\" mode (Ctrl-C to abort)..."
         ser = serial.Serial(self.serial.port,
                             self.serial.baudrate)  # Open XBee serial port
         xbee = XBee(ser)  # Create XBee object to manage packets
         dispatch = Dispatch(
             xbee=xbee
         )  # Start the dispatcher that will call packet handlers
         #            switchColor(WATCH_OUTPUT_TEXT)
         try:
             dispatch.run(
             )  # run() will loop infinitely while waiting for and processing packets which arrive.
         except KeyboardInterrupt:
             printc("\n*** Ctrl-C keyboard interrupt ***", ERROR_TEXT)
         ser.close()
         switchColor(WATCH_OUTPUT_TEXT)
示例#5
0
    # post startup message to other XBee's and at stdout
    serial.writelines("RPi #1 is up and running.\r\n")
    print "RPi #1 is up and running."

    switchColor(CMD_OUTPUT_TEXT)
    print "Entering loop to read and print messages (Ctrl-C to abort)..."

    try:
        while True:
            # read a line from XBee and convert it from b'xxx\r\n' to xxx and print at stdout
            switchColor(TERM_OUTPUT_TEXT)
            line = serial.readline().decode('utf-8')
            if line:
                print line

            # read data from the keyboard (i.e. stdin) and send via the XBee modem
            switchColor(TERM_INPUT_TEXT)
            try:
                line = sys.stdin.readline()
                serial.writelines(line)
            except IOError:
                time.sleep(0.1)
                continue

    except KeyboardInterrupt:
        printc("\n*** Ctrl-C keyboard interrupt ***", ERROR_TEXT)
        serial.writelines("RPi #1 is going down.\r\n")

    finally:
        switchColor(CMD_INPUT_TEXT)
示例#6
0
    # post startup message to other XBee's and at stdout
    serial.writelines("RPi #1 is up and running.\r\n")
    print "RPi #1 is up and running."

    switchColor(CMD_OUTPUT_TEXT)
    print "Entering loop to read and print messages (Ctrl-C to abort)..."

    try:
        while True:
            # read a line from XBee and convert it from b'xxx\r\n' to xxx and print at stdout
            switchColor(TERM_OUTPUT_TEXT)
            line = serial.readline().decode("utf-8")
            if line:
                print line

            # read data from the keyboard (i.e. stdin) and send via the XBee modem
            switchColor(TERM_INPUT_TEXT)
            try:
                line = sys.stdin.readline()
                serial.writelines(line)
            except IOError:
                time.sleep(0.1)
                continue

    except KeyboardInterrupt:
        printc("\n*** Ctrl-C keyboard interrupt ***", ERROR_TEXT)
        serial.writelines("RPi #1 is going down.\r\n")

    finally:
        switchColor(CMD_INPUT_TEXT)