首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Digi XBee Python模块将API帧发送到远程XBee?

如何使用Digi XBee Python模块将API帧发送到远程XBee?
EN

Stack Overflow用户
提问于 2020-06-06 01:04:41
回答 1查看 777关注 0票数 2

我正在将代码从Python库转移到Digi的Python库中,但是我在文档中找不到关于如何将XBee帧发送到远程XBee的语法。我使用的是S1和Beaglebone Pro设备,它们的“本地”设备连接到S1上,而“远程”设备在野外是独立的。

我有一个基本的框架:

代码语言:javascript
复制
from digi.xbee.devices import XBeeDevice, RemoteXBeeDevice, XBee64BitAddress

PORT = '/dev/ttyO1'
BAUD = 9600
API_FRAME = 'long-hex-string-here'

local_xbee = XBeeDevice(PORT, BAUD)
local_xbee.open()

# Instantiate a remote XBee device object.
remote_xbee = RemoteXBeeDevice(local_xbee, XBee64BitAddress.from_hex_string("0013A20040DD7DCD"))

# Transmit frame to remote_xbee - unsure of correct method and syntax
# perhaps XBeePacket.create_packet(hex string here)
# local_xbee.send_data(remote_xbee, "api frame here?")  ??

local_xbee.close()

但是我无法找到如何传输我构造的API帧的语法。根据文档中的介绍部分,我认为这是正确的方法。我对广播到网络上的所有设备不感兴趣,而是对单播通信感兴趣。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-07 08:58:21

我有一些旧模型的源代码,当我可以让它工作的时候。

我有一些WiFi Xbee模块,我使用了一些转换板(基板)。我用它来连接Xbee从一台电脑到另一台电脑的通信,例如,随机桌面通过通用串行总线而不是通用异步收发器连接到BeagleBone黑色。因此,我将使用下面列出的源代码,将用于Xbee通信的USB加密狗从BBB连接到其他现场模块。

他们的I/O东西可以在这里找到:https://github.com/digidotcom/xbee-python/tree/master/examples/io

USB适配器板仅在其源中的一些线路中被证明在信号LED和其他传感器中有价值。

哦,你还需要他们现在所说的载波板。这就是我刚敲出的转接板。所以,如果你已经有了一个载板,在Linux中使用lsusb作为命令来找到你的USB“名称”。

因此,例如,如果lsusb启动/dev/ttyUSB0,那么这就是端口标识。

您可以使用lsusb中的该部分,然后在Digi的xtcu软件中更改您的xbee模块。

代码语言:javascript
复制
from digi.xbee.devices import XBeeDevice
from digi.xbee.io import IOLine, IOMode
import time
import threading

# TODO: Replace with the serial port where your local module is connected to.
PORT = "/dev/ttyUSB0"
# TODO: Replace with the baud rate of your local module.
BAUD_RATE = 9600

REMOTE_NODE_ID = "Xbee_B"

IOLINE_IN = IOLine.DIO2_AD2
IOLINE_OUT = IOLine.DIO4_AD4

def main():
    print(" +-----------------------------------------------+")
    print(" | XBee Python Library Get/Set Remote DIO Sample |")
    print(" +-----------------------------------------------+\n")

    stop = False
    th = None

    local_device = XBeeDevice(PORT, BAUD_RATE)

    try:
        local_device.open()
        print("local device: ", local_device.get_node_id())
        # Obtain the remote XBee device from the XBee network.
        xbee_network = local_device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if local_device is None:
            print("Could not find the remote device")
            exit(2)

        def io_detection_callback():
            while not stop:
                # Read the digital value from the input line.
                io_value = remote_device.get_dio_value(IOLINE_IN)
                print("%s: %s" % (IOLINE_IN, io_value))

                # Set the previous value to the local output line.
                local_device.set_dio_value(IOLINE_OUT, io_value)

                time.sleep(2)

        th = threading.Thread(target=io_detection_callback)

        remote_device.set_io_configuration(IOLINE_IN, IOMode.DIGITAL_IN)

        local_device.set_io_configuration(IOLINE_OUT, IOMode.DIGITAL_OUT_HIGH)

        time.sleep(1)
        th.start()

        input()

    finally:
        stop = True
        if th is not None and th.is_alive():
            th.join()
        if local_device is not None and local_device.is_open():
            local_device.close()


if __name__ == '__main__':
    main()

那么,请看源代码的PORT = "/dev/ttyUSB0“部分?

这就是我将Xbee模块连接到载波板,然后通过USB将载波板连接到BBB的位置。

嗯,这可能没有回答一个问题,但提供了更多关于如何处理Digi设备/模块的见解。

我还认为,如果您想冒险使用Xbee和BeagleBone黑色进行UART通信,可能会更复杂。我会继续搜索我的文本。

附注:这本书介绍了一些连接方法,实验10和实验16,你的"BBB“到UART,Xbee,以及如何通信。从这本书中获得所有的沟通想法有点太深入了,但仅此而已:

代码语言:javascript
复制
The Hands-on XBEE Lab Manual, Experiments that Teach you XBEE Wireless Communications – Jonathan A Titus
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62220616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档