def main():
    print(" +----------------------------------------------+")
    print(" | XBee Python Library Format Filesystem Sample |")
    print(" +----------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    filesystem_manager = LocalXBeeFileSystemManager(device)

    try:
        device.open()
        filesystem_manager = LocalXBeeFileSystemManager(device)
        print("Starting file system manager...", end=" ")
        filesystem_manager.connect()
        print("OK\n")

        get_fs_info(filesystem_manager)

        print("\nFormatting filesystem...", end=" ")
        filesystem_manager.format_filesystem()
        print("OK\n")

        get_fs_info(filesystem_manager)

    except (XBeeException, FileSystemException) as e:
        print("ERROR: %s" % str(e))
        exit(1)
    finally:
        if filesystem_manager.is_connected:
            print("\nStopping file system manager...", end=" ")
            filesystem_manager.disconnect()
            print("OK")
        if device is not None and device.is_open():
            device.close()
示例#2
0
def main():
    print(" +-------------------------------------------+")
    print(" | XBee Python Library List Directory Sample |")
    print(" +-------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    filesystem_manager = LocalXBeeFileSystemManager(device)

    try:
        device.open()
        filesystem_manager = LocalXBeeFileSystemManager(device)
        print("Starting file system manager...", end=" ")
        filesystem_manager.connect()
        print("OK\n")
        current_directory = filesystem_manager.get_current_directory()
        print("Current directory: %s" % current_directory)
        path_to_list = PATH_TO_LIST
        if path_to_list is None:
            path_to_list = current_directory
        files = filesystem_manager.list_directory(path_to_list)
        print("Contents of '%s':" % path_to_list)
        for file in files:
            print(str(file))
    except (XBeeException, FileSystemException) as e:
        print("ERROR: %s" % str(e))
        exit(1)
    finally:
        if filesystem_manager.is_connected:
            print("\nStopping file system manager...", end=" ")
            filesystem_manager.disconnect()
            print("OK")
        if device is not None and device.is_open():
            device.close()
示例#3
0
class OpenFileSystem:
    """
    OpenFileSystem is a context manager for digi.xbee.filesystem.LocalXBeeFileSystemManager.
    This class ensures that the serial port gets properly closed even an error occurs.
    """
    def __init__(self, xbee):
        self.fs = LocalXBeeFileSystemManager(xbee)

    def __enter__(self):
        log("Opening XBee 3 filesystem...")
        self.fs.connect()
        log("Opened XBee 3 filesystem.")
        return self.fs

    def __exit__(self, exc_type, exc_value, traceback):
        self.fs.disconnect()
        log("Closed XBee 3 filesystem.")
def main():
    print(" +-------------------------------------------------+")
    print(" | XBee Python Library Upload/Download File Sample |")
    print(" +-------------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    filesystem_manager = LocalXBeeFileSystemManager(device)

    try:
        device.open()
        filesystem_manager = LocalXBeeFileSystemManager(device)
        print("Starting file system manager...", end=" ")
        filesystem_manager.connect()
        print("OK")
        upload_path = os.path.join(UPLOAD_PATH, os.path.basename(FILE_PATH))
        filesystem_manager.put_file(FILE_PATH,
                                    upload_path,
                                    progress_callback=progress_upload_callback)
        download_path = os.path.join(DOWNLOAD_PATH,
                                     os.path.basename(FILE_PATH))
        filesystem_manager.get_file(
            upload_path,
            download_path,
            progress_callback=progress_download_callback)
        print("\nFile hash summary\n-----------------------")
        print("%s %s" % ("Local:".ljust(15), get_sha256_hash(FILE_PATH)))
        print("%s %s" % ("Uploaded:".ljust(15),
                         filesystem_manager.get_file_hash(upload_path)))
        print("%s %s\n" %
              ("Downloaded:".ljust(15), get_sha256_hash(download_path)))
    except (XBeeException, FileSystemException) as e:
        print("ERROR: %s" % str(e))
        exit(1)
    finally:
        if filesystem_manager.is_connected:
            print("Stopping file system manager...", end=" ")
            filesystem_manager.disconnect()
            print("OK")
        if device is not None and device.is_open():
            device.close()
示例#5
0
 def __init__(self, xbee):
     self.fs = LocalXBeeFileSystemManager(xbee)