Xbee 1(接收器)的序列号为0013A200409A1BB8
Xbee 2(发件人)的序列号为0013A200709A1BE9
我在下面包含了我的代码,这只是我在网上找到的示例代码.我的问题是我没有在适当的Xbee上收到任何东西.我完全不知道出了什么问题,我已经三次检查目标地址和两个Xbee的配置设置.
Xbee 2代码(发件人):
#! /usr/bin/pythonimport timefrom xbee import XBeeimport serialPORT = '/dev/ttyUSB0'BAUD_RATE = 9600# Open serial portser = serial.Serial(PORT,BAUD_RATE)# Create API objectxbee = XBee(ser,escaped=True)import pprintpprint.pprint(xbee.API_commands)DEST_ADDR_LONG = "\x00\x13\xA2\x00\x40\x9A\x1B\xB8"# Continuously read and print packetswhile True: try: print "send data" xbee.tx_long_addr(frame='0x1',dest_addr=DEST_ADDR_LONG,data='AB') time.sleep(1) except KeyboardInterrupt: breakser.close()
Xbee 1代码(接收器):
#! /usr/bin/pythonfrom xbee import XBeeimport serialPORT = '/dev/ttyUSB0'BAUD_RATE = 9600# Open serial portser = serial.Serial(PORT,escaped=True)# Continuously read and print packetswhile True: try: print "waiting" response = xbee.wait_read_frame() print response except KeyboardInterrupt: breakser.close()
当两个程序都在运行时,发送Xbee上的Tx指示灯闪烁,但我在接收Xbee上没有收到任何信息.有什么我想念的吗?谢谢你的时间!
解决方法 您使用的是XBee还是XBeePro?我有同样的问题,this post给了我很多帮助.尝试按以下方式修改Receiver Code:
import configimport serialimport timefrom xbee import ZigBeedef toHex(s): lst = [] for ch in s: hv = hex(ord(ch)).replace('0x','') if len(hv) == 1: hv = '0'+hv hv = '0x' + hv lst.append(hv)def decodeReceivedFrame(data): source_addr_long = toHex(data['source_addr_long']) source_addr = toHex(data['source_addr']) ID = data['ID'] samples = data['samples'] options = toHex(data['options']) return [source_addr_long,source_addr,ID,samples]PORT = '/dev/ttyUSB0'BAUD_RATE = 9600# Open serial portser = serial.Serial(PORT,BAUD_RATE)zb = ZigBee(ser,escaped = True)while True: try: data = zb.wait_read_frame() decodedData = decodeReceivedFrame(data) print decodedData except KeyboardInterrupt: break
在我的情况下,上面的代码输出以下内容:
[['0x00','0x13','0xa2','0x00','0x40','0x9b','0xaf','0x4e'],['0x68','0x3f'],'rx_io_data_long_addr',[{'adc-0': 524}]]
Here我共享控制器节点的配置设置(与X-CTU兼容)
总结以上是内存溢出为你收集整理的无法在API模式下使用Xbee发送/接收(python)全部内容,希望文章能够帮你解决无法在API模式下使用Xbee发送/接收(python)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)