示例#1
0
 def refreshSystem(self):  # 用于刷新全部系统信息
     Raw802Device.open()
     remote_device = RemoteXBeeDevice(
         Raw802Device, XBee64BitAddress.from_hex_string("0013A200415D2430"))
     Raw802Device.send_data(
         remote_device, " ")  # 二进制:0010 0000,0000为每次发送时的帧别信息,0000为接收平台所有信息
     Raw802Device.close()
示例#2
0
def start():
    try:
        # Create and open device on serial port
        device = Raw802Device(PORT, BAUD_RATE)
        device.open()
        # Execute
        run_in_parallel(subscription, handle_messages, args=(device,))

    except Exception as e:
        print('Failed. Retrying in 3secs:', e)

        time.sleep(3)
        start()
示例#3
0
 def getmodule(self):  # 要求平台发送模组信息,用于获得及刷新模组信息
     Raw802Device.open()
     remote_device = RemoteXBeeDevice(
         Raw802Device, XBee64BitAddress.from_hex_string("0013A200415D2430"))
     Raw802Device.send_data(
         remote_device,
         "“")  # 二进制:0010 0010,前0010为每次发送时的帧别信息,后0010为接收平台当前模组信息
     Raw802Device.close()
示例#4
0
 def terminalSignal(self):  # 用于获取平台本身的信息
     Raw802Device.open()
     remote_device = RemoteXBeeDevice(
         Raw802Device, XBee64BitAddress.from_hex_string("0013A200415D2430"))
     Raw802Device.send_data(
         remote_device,
         "!")  # 二进制:0010 0001,0010为每次发送时的帧别信息,0001为接收平台当前除模组信息外的信息
     Raw802Device.close()
示例#5
0
文件: make.py 项目: dancullen/xbf
def main() -> Error:

    args = parse_arguments()

    if args.build:
        log("Building .mpy files...")
        err = build_mpy(src_dirs=SRC_DIRS, build_dir=BUILD_DIR)
        if err:
            log("Failed to build .mpy files. Details: %s" % err)
            return Error()
        log("Build .mpy files succeeded.")

    if args.deploy:
        log("Deploying .mpy files...")

        original_mode, err = ensure_api_mode(port=args.port,
                                             baud_rate=args.baud)
        if err:
            log("Error: Failed to enter API Mode! Details: %s" % err)
            return Error()

        with OpenXBeeDevice(xbee=Raw802Device(port=args.port,
                                              baud_rate=args.baud)) as xbee:
            err = ensure_running_latest_micropython_app(build_dir=BUILD_DIR,
                                                        xbee=xbee)
            if err:
                log("Error: Failed to deploy .mpy files. Details: %s" % err)
                return Error()
            log("Deploy .mpy files succeeded.")

        err = restore_mode(port=args.port,
                           baud_rate=args.baud,
                           original_mode=original_mode)
        if err:
            log("Error: Failed to restore original operating mode! Details: %s"
                % err)
            return Error()

    if args.deploy_remote:
        log("NOT IMPLEMENTED YET!")
        return Error()

    return Success
示例#6
0
def main():
    print(" +-----------------------------------------+")
    print(" | XBee Python Library Receive Data Sample |")
    print(" +-----------------------------------------+\n")

    device = Raw802Device(PORT, BAUD_RATE)


    try:
        device.open()

        def data_receive_callback(xbee_message):
            print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(),
                                     type(xbee_message.data.hex())))

        device.add_data_received_callback(data_receive_callback)

        print("Waiting for data...\n")
        input()

    finally:
        if device is not None and device.is_open():
            device.close()
示例#7
0
    def __init__(self,
                 port='/dev/tty.usbserial-DN050I6Q',
                 baud_rate=9600,
                 debug=0):
        '''

        ## Arguments
        ---

        | Argument  | Type     | Description                                | Default Value                       |
        | :------:  | :--:     | :---------:                                | :-----------:                       |
        | port      | `string` | USB port to open for local XBee            | set for your own convenience |
        | baud_rate | `int`    | Baud rate to use for USB serial port       | 9600                                |
        | debug     | `int`    | Enables/disables print statements in class | 0                                   |
        |<img width=400/>|<img width=250/>|<img width=1000/>|<img width=550/>|

        '''

        self.base = Raw802Device(port, baud_rate)
        self.debug = debug
        self.open_base()
        self.callbacks_added = False
        self.ascii_offset = 32
from digi.xbee.devices import Raw802Device

port0 = "/dev/ttyUSB0"
port1 = "/dev/ttyUSB1"
br = 115200
dataToSend = "abc"
d0 = Raw802Device(port0, br)
d0.open()
d1 = Raw802Device(port1, br)
d1.open()

示例#9
0
def run_server():
    """
    Xbee Server
    :return:
    """
    # INIT SERVER
    print("starting run_server...")
    UpdaWear.reset()
    MessageBuffer.clear()

    server = Raw802Device(PORT, BAUD_RATE)
    UpdaWear.id = "UPDA-WEAR-1"
    UpdaWear.address = XBee16BitAddress.from_hex_string(WEAR_16B_ADDR)
    UpdaWear.remote = RemoteRaw802Device(server, UpdaWear.address)
    instance_manager = None
    exit_message = bytearray([0x05, 0x00])

    try:
        # might not want this
        if not os.path.exists('./data'):
            print("unable to find './data' to store information")
            raise KeyboardInterrupt

        # get data count to make a new file
        num_patients = len([name for name in os.listdir('./data')])

        instance_manager = InstanceLoader(num_patients)
        instance_manager.start()  # start the thread
        server.open()

        def msg_callback(message):
            UpdaWear.received_count = UpdaWear.received_count + 1
            # register the device
            # print("{} >> {}".format(server.get_16bit_addr(), message.data.decode()))
            # pass information off to a buffer
            # store the data (byte array)
            with BufferLock:
                MessageBuffer.append(message.data)

        server.add_data_received_callback(msg_callback)

        print("press enter to stop run_server...")
        input()

    except KeyboardInterrupt:
        print()  # add a space so everything is nearly on a different line

    except serial.serialutil.SerialException:
        print("Unable to open {}".format(PORT))

    finally:

        if instance_manager is not None:
            # close instance manager
            with BufferLock:
                MessageBuffer.append(exit_message)
            instance_manager.join()

        if server is not None and server.is_open():
            server.close()

    print("closing run_server...")
示例#10
0
def establish_connection(
        address):  # 首次建立连接时使用,平台端接收到电脑端的地址即成功,但是python的16进制实在操蛋,字符串先将就着用用
    remote_device = RemoteXBeeDevice(Raw802Device,
                                     XBee64BitAddress.from_hex_string(address))
    Raw802Device.send_data(remote_device,
                           "\x75\x03" + str(Raw802Device.get_64bit_addr()))
示例#11
0
                                     XBee64BitAddress.from_hex_string(address))
    Raw802Device.send_data(remote_device,
                           "\x75\x03" + str(Raw802Device.get_64bit_addr()))


def terminal_signal_get(terminal_data):  # 获得并显示系统当前的信息,默认电量信息在前,模组数量信息在后
    for i in range(0, int(terminal_data[0:2], 16)):
        if terminal_data[(2 + 4 * i):(4 + 4 * i)] == '01':  # ‘01’表示平台电量,默认其在前
            print('电量:' + str(int(terminal_data[4 + 4 * i:6 + 4 * i])))
        elif terminal_data[(2 + 4 * i):(4 + 4 * i)] == '02':  # ‘02’表示模组数量,默认在后
            print('现加载的模组数:' + str(int(terminal_data[4 + 4 * i:6 + 4 * i])))


def module_signal_get(module_data):
    module_type = {"01": "空气质量检测", "02": "环境温度检测"}
    for i in range(0, int(module_data[0:2], 16)):
        print(module_type.get(module_data[(2 + 4 * i):(4 + 4 * i)]))


mode_choose = 2333
while mode_choose != -1:
    com = input('给我自己输入接的哪个usb口,记得大写:')
    Raw802Device = Raw802Device(com, 115200)
    try:
        Raw802Device.open()
        Raw802Device.add_data_received_callback(switch_case)
        Raw802Device.close()
    finally:
        pass
    mode_choose = input('输入-1退出,不退出的话就随便输个数:')
示例#12
0
#!/usr/bin/env python
# Time    : 2021/3/2 20:26
# Author  : RummySaltyfish
from digi.xbee.devices import RemoteXBeeDevice, Raw802Device
from digi.xbee.models.address import XBee64BitAddress

Device802 = Raw802Device("COM4", 115200)
Device802.open()


def data_receive_callback(xbee_message):
    print(
        "From %s >> %s" %
        (xbee_message.remote_device.get_64bit_addr(), xbee_message.data.hex()))


Device802.add_data_received_callback(data_receive_callback)
Device802.close()
示例#13
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time    : 2021/1/28 12:57
# Author  : RummySaltyfish

from digi.xbee.devices import RemoteXBeeDevice, Raw802Device
from digi.xbee.models.address import XBee64BitAddress

data_send = bin(25)
# Instantiate an XBee device object.
local_xbee = Raw802Device("COM3", 115200)
local_xbee.open()
remote_xbee = RemoteXBeeDevice(
    local_xbee, XBee64BitAddress.from_hex_string("0013A200415D2430"))
local_xbee.send_data(remote_xbee, data_send)
local_xbee.close()