Description

Open a file for reading and/or writing.

  • Requests must have at least READ or WRITE bit set in the Options field.

  • Use the SECURE bit (0x80) of the Options byte to upload a write-only file (one that cannot be downloaded or viewed). This is useful for protecting MicroPython source code on the device.

  • The SECURE bit is only valid when also setting the WRITE bit and either creating a new file (CREATE + EXCLUSIVE) or replacing an existing file (TRUNCATE).

Format

Offset Size Frame Field Description

5

8-bit

File System Command

File Open - 0x01

6

16-bit

Path ID

See Get Path ID - 0x1C for a description

8

8-bit

Options

Bitfield with the following values:

  • 0x01 CREATE: Create if file doesn’t exist.

  • 0x02 EXCLUSIVE: Error out if file exists.

  • 0x04 READ: Open file for reading.

  • 0x08 WRITE: Open file for writing.

  • 0x10 TRUNCATE: Truncate file to 0 bytes.

  • 0x20 APPEND: Append to end of file.

  • 0x40 UNUSED: Unused, set to 0.

  • 0x80 SECURE: Create a secure write-only file.

9-n

8-bit

File Name

Pathname relative to Path ID.

Success Response

Offset Size Frame Field Description

5

8-bit

File System Command

File Open - 0x01

6

8-bit

Status

Success - 0x00

7

16-bit

File Handle

Value used to reference file in later requests. Expires and becomes invalid if not referenced for over 2 minutes.

9

8-bit

File Size

File’s size or 0xFFFFFFFF if unknown.