Lego NXT File Handling- Introduction
By Anna Sandler
This is an advanced topic, please familiarize yourself with
"What is a NXT Bluetooth Telegram" tutorial before you continue reading
this chapter.
Files handling command types
Files handling commands are part of the "System commands".
There are two relevant command types for a system command:
- 0x01 for a command with reply message, and
- 0x81 for a command without the reply message.
Some of the file handling commands require a reply message such as open file commands
or a read command.
File names
File name format consists from:
[name, up to 15 ASCII characters].[type, 3 ASCII characters][string null terminator
0x00].
The system is case insensitive, meaning uppercase characters are treated the same
as lower case characters.
File types
The following file types are supported:
- RXE: NXT’s executable files, compiled from NXT-G, LabVIEW, or another compatible
programming environment.
- RPG: 5-step programs created using the “NXT Program” user interface on the
NXT brick.
- RTM: Built-in “Try Me” programs.
- RIC: Image files for use with the NXTDrawPicture syscall method in .RXE programs.
- RSO: Sound files.
- SYS: Internal NXT firmware files.
- CAL: Sensor calibration file.
- TXT: ASCII text file using carriage return/line feed (CR/LF, Windows) end-of-line
convention.
- LOG: Also an ASCII text file, created by the NXT data logging functionality.
File handling workflow
On the NXT brick’s flash memory, files are organized in a simple, flat, file-system
without folders.
File should be opened first before read or write.
The return message of the opening commands includes the handler id of the opened
file.
The system registers each handler ids and its file name that is currently opened
in an internal table.
Retrieving an opened handler id is always possible using the ResolveHandle command
that gets the file name and retrieved open file handler id (will be discussed in
later posts).
Open handlers must be closed when are no longer in use.
All open handlers are closed automatically at the end of the program execution.
When the file is closed automatically, unused space inside the specified file is
removed, in order to maximize the free space on the device.
Limitations:
- 16 open handlers (read and write) for each thread;
- 4 open handlers for writing purposes at the same time;
- 127 maximum files can be created in the system. (If there is enough free
space.)
- A delay of 6 milliseconds must be passed between the file handling command
and any other command.
- File name is allowed to be up to 15 characters, plus 3 characters
for the file type and a NULL terminator ('\0')
- Telegram length is limited to 64 bytes.
File handling errors
File handling commands return a descriptive error reason for failure at the reply
message (if requested).
Open file commands will retrieve a fake handler id in case of failure.
The error code can be found in the status byte of each response command.
The following is a list of file handling errors:
- 0x00- Success - the command that has requested this response has been successfully
executed.
- 0x81- No more handlers. The system is not able to allocate any more file
handlers for this thread. One of the reasons for this error can be a maximum limit
of 16 opened file handlers that has already been reached for this thread. Try to
send CloseFile command to one of the open file handlers that is no longer in use,
then resend the open file command again.
- 0x82- No space
- 0x83- No more files. The system is not able to create any more files. Most likely, the reason is that you’ve reached the limitation of 127 files the can be
saved on the NXT brick’s flash memory. Try deleting files that are not in use and
resend the create file command again.
- 0x84- End of file expected. Write request exceeded the space available for
the file. Partial write performed. One of the reasons can be a wrong file size calculation
when it was created due to missing null terminator bytes after the file name in
case the name is shorter than 15 characters.
- 0x85- End of file. File operation reached the end of the file.
- 0x86- Not a linear file.
- 0x87- Specified file not found.
- 0x88- Handler already closed.
- 0x89- No linear space. The system is not able to allocate requested linear
file system space for specific file.
- 0x8A- Undefined error.
- 0x8B- File is busy. The system cannot acquire file handler for specified
file because some other operation has opened the file.
- 0x8C- No write buffers. The system cannot open the file for write operation
because all write buffers are already in use. There is a limitation of 4 files that
can be opened for writing at the same time. Try to close one of the opened files
that are no longer is use and resend the open file for write command.
- 0x8D- Append is impossible. Not a textual file or the file is already full.
The only way to use FileOpenAppend command successfully, is to create a textual
file, leave some empty space and close it using the FileClose command.
Bear in mind that once the file is automatically closed by the file system, all
the free space in the file is removed to optimize total free space in the brick.
- 0x8E- File is full. The allocated space for specified file is full. No more
write operations allowed.
- 0x8F- File name exists. The system has failed to create or rename the file due
to name collision. Try to resend the command with different name.
- 0x92- Illegal file name. The file name that has been provided is illegal.
Make sure that the correct file name format is used: [15].[3] characters.
File type can be only one of the types that has been described in the file types
section above.
- 0x93- Illegal handler. the allocated space for specified file is full, or the
file has been opened for other purposes.
What's next?
my wife cheated now what
read looking for affair
abortion cost without insurance
site post abortion
canada drug pharmacy coupon
internet drug coupons