Robot App Store Developer Program

robots-app-store-developer-program

Knowledge Base

Lego NXT File Handling- Delete Files

  By Anna Sandler

This is an advanced topic, please make sure you've read the "Introduction To File Handling" tutorial before you continue reading this chapter.



FileDelete command

This command is used to delete unused files from the file system.

When a file is deleted successfully, the following operations are performed:
  • Specified file is physically removed from the file system.
  • Pending file write buffers are committed to flash memory.
  • Make sure to use the FileClose command (if it was previously opened in current program run-time) before calling the FileDelete command.
There is a limitation of 127 files that can be created in the system. (If there is enough free space).
Make sure to delete all the files that are not needed to free space in the file system.

Syntax

[0x16] [0x00] [0x01 or 0x81] [0x85] [fileName.fileType]

Explanation:

  • Byte 0-1: Command length LSB first.
  • Byte 2: Command type- system command. For system command with response message use 0x01, otherwise, for system command without the reply message, use 0x81.
  • Byte 3: Command- file delete.
  • Byte 4-23: A file name of an existing and closed file on NXT's brick, including its extension. The system is case insensitive.
    The bytes of file name and type characters should be ASCII encoded.
    NULL terminator must appear at the end ('\0').
    In case the name of the file is shorter than 15 characters, NULL terminator byte should be added to the end of the file name extension for each missing character.
    Total file name characters, including the NULL terminators, should always be 20.

The reply message that is coming back (if requested) looks like:

[0x17] [0x00] [0x02] [0x85] [0x00 or error] [fileName.fileType]

Explanation:

  • Byte 0-1: Message length LSB first.
  • Byte 2: Command type- reply message
  • Byte 3: Command that has requested for this reply.
  • Byte 4: Command status- 0x00 for success or error number for failure. Check the NXT File Handling over Bluetooth- Introduction chapter for error numbers. Most popular failures are when specified file name doesn’t exist or is currently opened.
  • Byte 5-24: File name. The name of the file that has been requested to be deleted. The bytes of file name and type characters are ASCII encoded. NULL terminator appears at the end of the name (\0).

Example:

The file RobotAppStore1.txt is requested to be deleted.

The command that is sent to NXT is:
0x16 0x00 0x01 0x85 RobotAppStore1.txt\0\0

The command that is received from NXT as a reply is:
0x17 0x00 0x02 0x85 0x00 RobotAppStore1.txt\0\0

What's next?

Let's move forward and learn NXT File Handling- Search Files

wifes who cheat cheat women women who cheat on their husband







Related Robot-Apps™

Comments