Python while循环让我疯了!请

时间:2015-11-18 16:48:20

标签: python loops while-loop

该脚本应该连续读取不同的rfid标签,打印出标签号并将其发送到远程xbee。但是,它会持续不断地读取标签。我希望它在显示结果后读取标签并将其发送到远程xbee,然后等待不同的标签并重复该过程。

onValue

1 个答案:

答案 0 :(得分:0)

def main():
    ann = as3992_api.AntennaDevice()

    print "Firmware info: %s\nHardware info: %s" % ann.get_system_info()
    print "Activating antenna"
    ann.set_antenna_state(True)
    print " Reading Tags:"
    ok=[]
    while True:
        try:
            for epc, rssi in ann.iter_epc_rssi():
                if epc+rssi not in ok:
                    #time.sleep(1)
                    print "---------------------------------------"
                    print "Scanning Tag..."
                    time.sleep(1)
                    print "Tag code epc:" +epc.encode("HEX"),rssi
                    #send tag info to remote xbee

                    xbee.tx_long_addr(frame='0x1', dest_addr=XBEE1_ADDR_LONG, data=epc.encode("HEX"))
                    print "---------------------------------------"
                    time.sleep(1)
                    print "Sending tag information to XBee 1 ..."
                    ok.append( epc+rssi )
        except KeyboardInterrupt:
            ann.set_antenna_state(False)
            break