Contenido principal

read

R2026b

Read file from remote MAVLink client

Since R2026b

    Description

    [status,data] = read(ftp,mavlinkclient,filePath) reads the file filePath from the MAVLink client mavlinkclient using burst mode.

    [status,data] = read(___,Name=Value) specifies options using one or more name‑value arguments in addition to the input arguments from the previous syntax. For example, LocalPath="logs/flight1.ulg" saves the flight1.ulg file to the logs folder.

    Tip

    To save the file to disk, specify the LocalPath name‑value argument. If you do not specify LocalPath, the function reads the file contents but does not save the file.

    example

    Examples

    collapse all

    Download and delete flight logs from a Pixhawk® 4 board running PX4® firmware by using the FTP microservice.

    Download the latest version of common.xml file from the MAVLINK Common Message Set (common.xml) section of the MAVLink documentation, then create a mavlinkdialect object using the file.

    dialect = mavlinkdialect("common.xml");

    Create a local MAVLink client by using the mavlinkio object.

    gcs = mavlinkio(dialect);

    Store the remote MAVLink client information by using the mavlinkclient object. This Pixhawk board has a system ID of 1 and a component ID of 1.

    uav = mavlinkclient(gcs,1,1);

    Connect the local MAVLink client to the same serial port as the Pixhawk board by using the connect function. This Pixhawk board uses the COM5 port.

    connect(gcs,"Serial",SerialPort="COM5");

    Create a heartbeat microservice object.

    heartbeat = mavlinkmicroservice(gcs,"heartbeat");

    Start sending the HEARTBEAT messages to the Pixhawk board by using the start function.

    start(heartbeat,uav,"Serial",SerialPort="COM5")

    If the Pixhawk board replies with HEARTBEAT messages, a connection is established.

    Verify that the connection has been established by using the listClients function.

    listClients(gcs)
    ans = 2×4 table
        SystemID    ComponentID       ComponentType             AutopilotType     
        ________    ___________    ____________________    _______________________
    
          255            1            "MAV_TYPE_GCS"        "MAV_AUTOPILOT_INVALID"
           1             1         "MAV_TYPE_QUADROTOR"       "MAV_AUTOPILOT_PX4"

    Create an FTP microservice object.

    ftp = mavlinkmicroservice(gcs,"ftp");

    List the available flight logs stored in the /fs/microsd/log directory of the Pixhawk board by using the list function.

    [status,directory] = list(ftp,uav,"/fs/microsd/log")
    status = true
    directory = 4×3 table
          Type           Name            Size                 
        ________    _______________    _________  
    
          File       2026-03-01.ulg     7340032 
          File       2026-03-02.ulg     7540432 
          File       2026-03-03.ulg     6320031 
          File       2026-03-04.ulg     8221332 
    

    Download the 2026-03-02.ulg flight log into the Documents/logs directory by using the read function.

    [status,~] = read(ftp,uav,"/fs/microsd/log/2026-03-02.ulg", ... 
    LocalPath="Document/logs/2026-03-02.ulg")
    status = true

    After you have downloaded the 2026-03-02.ulg flight log, delete the flight log from the Pixhawk board to save memory space by using the remove function.

    status = remove(ftp,uav,"/fs/microsd/log/2026-03-02.ulg")
    status = true

    Verify that the file has been deleted by using the list function again.

    [status,directory] = list(ftp,uav,"/fs/microsd/log")
    status = true
    directory = 3×3 table
          Type           Name            Size                 
        ________    _______________    _________  
    
          File       2026-03-01.ulg     7340032 
          File       2026-03-03.ulg     6320031 
          File       2026-03-04.ulg     8221332 
    

    Input Arguments

    collapse all

    FTP microservice, specified as a ftpMicroservice object.

    Remote MAVLink client information, specified as a mavlinkclient object.

    The remote file path to read from the MAVLink client, specified as a string scalar.

    Example: "/fs/microsd/log/2026-03-02/00000123.ulg"

    Data Types: string

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: read(ftp,mavlinkclient,filePath,Mode="Normal") reads the file specified in filePath using normal mode.

    Local file path to which to save the file, specified as a string scalar.

    Example: "logs/flight1.ulg"

    Data Types: string

    Read mode, specified as one of these options:

    • "Burst" — The remote MAVLink client sends file chunks continuously without awaiting acknowledgment for each chunk. This option enables faster file reading. Choose this option to read large files.

    • "Normal" — The remote MAVLink client waits for acknowledgment for each file chunk transferred. Choose this option to read files with a size of under 5 KB.

    Data Types: string

    Output Arguments

    collapse all

    File download status, returned as a 1 or 0 of data type logical. The value is 1 (true) when all requested file chunks are downloaded.

    Data Types: logical

    Downloaded file contents, returned as raw bytes in a vector of integers.

    Data Types: uint8

    Version History

    Introduced in R2026b