Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The io.open() function is used to open the file on SD card for subsequent reading or writing. After the script is done with the file manipulation io.close() function should be used.
filename
full path to the file starting from the SD card root directory. This function can't create a new file in non-existing directory.
mode
supported mode strings are:
"r"
read access. File must exist beforehand. The read pointer is located at the beginning of file. This is the default mode if is omitted.
"w"
write access. File is opened or created (if it didn't exist) and truncated (all existing file contents are lost).
"a" write access. File is opened or created (if it didn't exist) and write pointer is located at the end of the file. The existing file contents are preserved.
<file object>
if file was successfully opened.
nil
if file could not be opened.
The io.write() function is used to write data to the file on SD card.
file object
a file object that was returned by the io.open() function. The file must be opened in write or append mode.
data
any Lua type that can be converted into string. If more than one data parameter is used their contents are written to the file by one in the same order as they are specified.
<file object>
if data was successfully opened.
nil, <error string>, <error number>
if the data can't be written.
The io library has been simplified and only a subset of functions and their functionality is available. What follows is a complete reference of io functions that are available to EdgeTX scripts
io.open()
io.close()
io.read()
io.write()
io.seek()
The io.read() function is used to read data from the file on SD card.
Notice: other read commands (like "all", etc..) are *not supported.
file object
a file object that was returned by the io.open() function. The file must be opened in read mode.
length
number of characters/bytes to read. The number of actual read/returned characters can be less if the file end is reached.
<string>
a string with a length equal or less than
""
a zero length string if the end of file was reached
Lua Standard Libraries | Included |
---|---|
package
-
coroutine
-
table
since OpenTX 2.3.8
(color LCD radios only)
since OpenTX 2.1.0 (with limitations)
os
-
string
since OpenTX 2.1.7
bit32
since OpenTX 2.1.0
math
since OpenTX 2.0.0
debug
-
The io.seek() function is used to move the current read/write position.
Notice: other read standard seek bases (like "cur", "end") are not supported.
file object
a file object that was returned by the io.open() function.
offset
position the read/write file pointer at the specified offset from the beginning of the file. If specified offset is bigger than the file size, then the pointer is moved to the end of the file.
0
success
<number>
any other value means failure.