Ejemplo n.º 1
0
def main():

    print(" +-------------------+")
    print(" | Send Data 16 Test |")
    print(" +-------------------+\n")

    local = XBeeDevice(PORT_LOCAL, BAUD_RATE_LOCAL)
    local_remote = XBeeDevice(PORT_REMOTE, BAUD_RATE_REMOTE)

    try:
        local.open()
        local_remote.open()

        remote = RemoteXBeeDevice(local,
                                  x16bit_addr=local_remote.get_16bit_addr())
        local.send_data(remote, "Test message")

        time.sleep(1)

        message = local_remote.read_data()
        assert (message is not None)
        assert (
            message.remote_device.get_16bit_addr() == local.get_16bit_addr())

        print("Test finished successfully")

    finally:
        if local is not None and local.is_open():
            local.close()
        if local_remote is not None and local_remote.is_open():
            local_remote.close()
def main():

    print(" +-----------------------------+")
    print(" | Add Remote Device by Reader |")
    print(" +-----------------------------+\n")

    device_a = XBeeDevice(PORT_A, BAUD_RATE_A)
    device_b = XBeeDevice(PORT_B, BAUD_RATE_B)

    try:
        device_a.open()
        device_b.open()

        network = device_a.get_network()

        remote = RemoteXBeeDevice(device_b, device_a.get_64bit_addr())

        # Send a message from B to A.
        device_b.send_data(remote, "Test")

        # Give some time to device A to receive the packet.
        time.sleep(1)

        # Check that B is in the network of A.
        assert (len(network.get_devices()) == 1)
        try:
            assert (network.get_device_by_64(
                device_b.get_64bit_addr()) == device_b)
        except AssertionError:
            assert (network.get_device_by_16(
                device_b.get_16bit_addr()).get_16bit_addr() ==
                    device_b.get_16bit_addr())

        # Send another message from B to A.
        device_b.send_data(remote, "Test")

        # Check that B is not duplicated.
        assert (len(network.get_devices()) == 1)
        try:
            assert (network.get_device_by_64(
                device_b.get_64bit_addr()) == device_b)
        except AssertionError:
            assert (network.get_device_by_16(
                device_b.get_16bit_addr()).get_16bit_addr() ==
                    device_b.get_16bit_addr())

        print("Test finished successfully")

    finally:
        if device_a is not None and device_a.is_open():
            device_a.close()
        if device_b is not None and device_b.is_open():
            device_b.close()
def main():
    print(" +-----------------------------------------------------+")
    print(" | XBee Python Library Manage Common parameters Sample |")
    print(" +-----------------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        print("Cached parameters\n" + "-" * 50)
        print("64-bit address:   %s" % device.get_64bit_addr())
        print("16-bit address:   %s" % device.get_16bit_addr())
        print("Node Identifier:  %s" % device.get_node_id())
        print("Firmware version: %s" %
              utils.hex_to_string(device.get_firmware_version()))
        print("Hardware version: %s" %
              device.get_hardware_version().description)

        print("")

        # Configure and read non-cached parameters.
        device.set_pan_id(PARAM_VALUE_PAN_ID)
        device.set_dest_address(PARAM_DESTINATION_ADDR)
        device.set_power_level(PARAM_POWER_LEVEL)

        print("Non-Cached parameters\n" + "-" * 50)
        print("PAN ID:           %s" %
              utils.hex_to_string(device.get_pan_id()))
        print("Dest address:     %s" % device.get_dest_address())
        print("Power level:      %s" % device.get_power_level().description)

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 4
0
def run():
    global device
    #dev_logger = utils.enable_logger("digi.xbee.devices", logging.DEBUG)
    dev_logger = utils.disable_logger("digi.xbee.devices")
###################################################################################################
#    Look for XBee USB port, to avoid conflicts with other USB devices
###################################################################################################
    rospy.init_node('fleetCoordinator', anonymous=True)

    rospy.loginfo("Looking for XBee...")

    context = pyudev.Context()
    usbPort = 'No XBee found'

    for device in context.list_devices(subsystem='tty'):
        if 'ID_VENDOR' in device and device['ID_VENDOR'] == 'FTDI':
            usbPort = device['DEVNAME']

    device = XBeeDevice(usbPort, 57600)
    #device = XBeeDevice("/dev/ttyUSB0", 57600)
    device.open()
    print("Current timeout: %d seconds" % device.get_sync_ops_timeout())
    device.set_sync_ops_timeout(0.1)

###################################################################################################
#    Get local XBee ID (should be 0, convention for Coordinator)
###################################################################################################
    ID = utils.bytes_to_int(device.get_16bit_addr().address)

    if ID == 0:
        rospy.loginfo("\nHello,\nI am Coordinator " + str(ID)+'\n')
    else:
        raise Exception("This XBee device is not the coordinator of the network,\nlook for the XBee device stamped with 'C'.")


###################################################################################################
#    Initialisation
###################################################################################################
    #Variables storing the data received by the subscribers
    global remote_devices, pubGps, pubEuler, pubLB, pubLE, lastDataStr, lastData
    remote_devices = {}
    lastDataStr = {}
    lastData = {}
    pubGps = []
    pubEuler = []
    pubLB = []
    pubLE = []

    xnet = device.get_network()
    xnet.add_device_discovered_callback(network_callback)
    xnet.add_discovery_process_finished_callback(network_finished)
    device.add_data_received_callback(data_received)

    rate = rospy.Rate(10)

    GPSdata = GPSFix()
    eulerAnglesData = Vector3()
    lineStartData, lineEndData = Pose2D(), Pose2D()

    global chosen, mode, cmd
    mode = 0
    chosen = 0
    cmd = Twist()

    pygame.init()
    screen = pygame.display.set_mode( (640,480) )
    pygame.display.set_caption('Python numbers')


###################################################################################################
# Transmission Loop
###################################################################################################

    while not rospy.is_shutdown():
        if(xnet.is_discovery_running() is False):
            xnet.start_discovery_process()

        display(screen)

        send_command()

        rate.sleep()

    if(xnet.is_discovery_running()):
        xnet.stop_discovery_process()
    device.close()
Ejemplo n.º 5
0
from digi.xbee.devices import XBeeDevice
device = XBeeDevice("/dev/ttyUSB0", 9600)
device.open()

print(device.read_device_info())

protocol = device.get_protocol()
print(protocol)


print("get_64bit_addr {}".format(device.get_64bit_addr()))
print("get_16bit_addr {}".format(device.get_16bit_addr()) )



device.close()