【发布时间】:2020-10-13 18:08:06
【问题描述】:
我正在尝试使用每次发送消息时都会更新的变量来更新字符串 (MESSAGE) (msg_no)
我查了一下,似乎 msg_no 变量正在按照我想要的方式更新,但字符串 (MESSAGE) 没有更新(每次都显示为 0)。我不知道为什么,谢谢你的帮助。
import xbee
import time
msg_no = 0
# TODO: replace with the 64-bit address of your target device.
TARGET_64BIT_ADDR = b'\x00\x13\xA2\x00\x41\xB7\x6C\x8C'
MESSAGE = "Hello from router (Msg No. %s)" % (msg_no)
print(" +---------------------------------------+")
print(" | XBee MicroPython Transmit Data Sample |")
print(" +---------------------------------------+\n")
print("Sending data to %s >> %s" % (''.join('{:02x}'.format(x).upper() for x in TARGET_64BIT_ADDR),
MESSAGE))
try:
msg_no += 1
xbee.transmit(TARGET_64BIT_ADDR, MESSAGE)
print("Data sent successfully")
except Exception as e:
print("Transmit failure: %s" % str(e))
time.sleep(5)
try:
msg_no += 1
MESSAGE = MESSAGE
xbee.transmit(TARGET_64BIT_ADDR, MESSAGE)
print("Data sent successfully")
except Exception as e:
print("Transmit failure: %s" % str(e))
【问题讨论】:
-
你永远不会更新
MESSAGE。MESSAGE = MESSAGE什么都不做 -
^ 正如 ted 所说,它没有被改变,% msg_no 你还想做什么?你的预期输出是什么...