Robot App Store

image description

Robopedia

LEGO NXT ignores the file size when it is created


Question


I am using the TextFileOpenWriteCreate command (0x8B).
The file that is actually created is smaller than the size that I send to the command.

Is that a bug in the communication protocol?

Answer


There are two possible reasons for the reduced file size:
  • Wrong command arguments- The size argument contains 4 bytes LSB first. If the bytes are mixed (MSB first), the file that is created will be different;
  • Automatically file size reduction by the firmware- When a text file is created, its size is determined by the file size argument of the command; however, its size can be reduced to its actual size (according to the number of written bytes) when the file is automatically closed by the firmware;

In order to create a text file correctly, make sure that:
  • The name of the file in the file create command is exactly 19 characters and 0x00 byte as NULL terminator. In case the file name is less than 19 characters, add 0x00 byte for each missing character. The bytes of file name and type characters should be ASCII encoded;
  • The file size is constructed from 4 bytes. LSB first. Check how to convert decimal to a byte array (MSB first) at the Robopedia and reverse the array to get the LSB first;
  • The file create command size is exactly 26 bytes 0x1A 0x00;
  • There is enough space for this size;
  • Use the FileWrite command to fill the file with data;
  • Call the FileClose command to save changes and prevent from the firmware to close the file automatically and reduce its size (if you need the extra space for future edit);

The syntax of the TextFileOpenWriteCreate command is:
[0x1A] [0x00] [0x01][0x8B] [fileName.fileType] [File size LSB] [...] [...] [File size MSB]

For more information about this command and its arguments check the file handling – create files tutorial.

The syntax of the FileWrite command is:
[0x04 - ???] [0x00- ???] [0x01 or 0x81] [0x83] [Handle id] [Data]

For more information about this command and its arguments check the file handling – write to file tutorial.

The syntax of the FileClose command is:
[0x03] [0x00] [0x01 or 0x81] [0x84] [Handle id]

For more information about this command and its arguments check the file handling – save and close tutorial.
read here cheats why men cheat on beautiful women
click why men have affairs married men having affairs
wifes who cheat cheat women women who cheat on their husband
abortion cost without insurance go post abortion



Related Robopedia portals

Find out further reading in the following topic-based portals.
[Add or Edit Article]