Hardware Reference
In-Depth Information
used to perform read-and-write functions. If the i le cannot be opened, the
File
object evaluates to
false
; it is therefore possible to test if the i le was opened:
File datafile = FileSystem.open("/data/log.txt", FILE_WRITE);
if (!datafile)
Serial.println("ERROR: File could not be opened!");
File operations are exactly like the SD-card library; functions such as
read()
,
write()
,
seek()
, and
flush()
exist. This library is similar in structure to the
SD library; only the underlying routines change. For more information, see
Chapter 12.
However, not every function works on i les.
open()
requires a folder to exist,
but it does not work if the folder does not exist and does not create a folder if
it is missing. To remedy this, various i lesystem instructions exist that do not
require a i le to perform actions.
To check if a i le exists without opening it (or creating a new one), use
exists()
:
result = FileSystem.exists(filename);
The
filename
parameter is a
String
and is in the same format as
open()
. It
returns a
boolean
:
true
if the i le (or folder) exists and
false
if it does not exist.
To create a folder, use
mkdir()
:
result = FileSystem.exists(filename);
This function returns a
boolean
:
true
if the folder were created,
false
otherwise. To delete a folder, use
rmdir()
:
result = FileSystem.rmdir(folder);
This function returns a
boolean
:
true
if the folder were deleted,
false
if the
function were unable to delete the folder. It requires the target folder to be empty;
any i les present must be removed. To remove i les, use
remove()
:
result = FileSystem.remove(filename);
This function, like the previous functions, returns a
boolean
:
true
if deleted,
false
otherwise. This function is a wrapper for the system command
rm
and
as such can delete both i les and folders.
YunSer ver
The YunServer class is used when creating a server on the Arduino Yún's Linux
distro. This allows the Arduino side of the Yún to receive requests and to answer
those requests.
To create a server, you must i rst create a YunServer object:
YunServer server;
When the object has been created, you must tell the Arduino who can con-
nect. Contrary to most Arduino Ethernet shields, you will not want external
Search WWH ::
Custom Search