无法发送/接收使用的XBee在API模式(蟒蛇) [英] Cannot send/receive using Xbee's in API mode (python)

查看:1031
本文介绍了无法发送/接收使用的XBee在API模式(蟒蛇)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个的XBee Pro的900的,每一个连接到树莓派。两者都更新为1061版和被设置为API来与逃逸启用。他们也有7FFF相同调制解调器VID。这两种皮的有库安装PySerial和蟒蛇-的XBee。

I have two Xbee Pro 900's, each attached to a Raspberry Pi. Both are updated to version 1061 and are set to API Enable with escapes. They also have the same Modem VID of 7FFF. Both Pi's have PySerial and the python-xbee library installed.

的Xbee 1(接收机)具有0013A200409A1BB8结果,序列号
的XBee 2(发件人)具有0013A200709A1BE9的序列号

Xbee 1(Receiver) has a serial number of 0013A200409A1BB8
Xbee 2(Sender) has a serial number of 0013A200709A1BE9

我包括我下面code,这仅仅是样品code,我在网上找到。我的问题是,我没有收到在适当的XBee什么。我绝对不知道什么是错的,我三重检查目的地址,以及两者的的XBee的配置设置。

I've included my code below, which is just sample code I've found online. My issue is that I'm not receiving anything on the appropriate Xbee. I have absolutely no idea what is wrong, I've triple checked the destination address, and both of the Xbee's configuration settings.

2的XBee code(发件人):

Xbee 2 Code(Sender):

#! /usr/bin/python

import time

from xbee import XBee
import serial

PORT = '/dev/ttyUSB0'
BAUD_RATE = 9600

# Open serial port
ser = serial.Serial(PORT, BAUD_RATE)

# Create API object
xbee = XBee(ser,escaped=True)
import pprint
pprint.pprint(xbee.api_commands)

DEST_ADDR_LONG = "\x00\x13\xA2\x00\x40\x9A\x1B\xB8"

# Continuously read and print packets
while True:
    try:
        print "send data"
        xbee.tx_long_addr(frame='0x1', dest_addr=DEST_ADDR_LONG, data='AB')
        time.sleep(1)
    except KeyboardInterrupt:
        break

ser.close()

的XBee 1 code(接收器):

Xbee 1 Code(Receiver):

#! /usr/bin/python

from xbee import XBee
import serial

PORT = '/dev/ttyUSB0'
BAUD_RATE = 9600

# Open serial port
ser = serial.Serial(PORT, BAUD_RATE)

# Create API object
xbee = XBee(ser,escaped=True)

# Continuously read and print packets
while True:
    try:
        print "waiting"
        response = xbee.wait_read_frame()
        print response
    except KeyboardInterrupt:
        break

ser.close()

在这两个程序正在运行,在发送的XBee与Tx灯闪烁,但我收到关于接受的XBee什么。有我丢失的东西?感谢您的时间!

When both programs are running, the Tx light on the sending Xbee blinks, but I receive nothing on the receiving Xbee. Is there something I'm missing? Thanks for your time!

推荐答案

您使用的XBee或XBeePro?我有rel=\"nofollow\">这个帖子帮了我很多同样的问题,

Are you using XBee or XBeePro? I had the same problem and this post helped me a lot.

尝试修改接收器code以下方式:

Try to modify the Receiver Code the following way:

import config
import serial
import time
from xbee import ZigBee

def 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 port
ser = 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

在我的情况下,code以上输出以下内容:

In my case the code above outputs the following:

[['0x00', '0x13', '0xa2', '0x00', '0x40', '0x9b', '0xaf', '0x4e'], ['0x68', '0x3f'], 'rx_io_data_long_addr', [{'adc-0': 524}]]

这里我共享的控制器节点配置设置(使用X-CTU兼容)

Here I shared configuration settings for Controller Node (compatible with X-CTU)

这篇关于无法发送/接收使用的XBee在API模式(蟒蛇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆