Hardware Reference
In-Depth Information
read() returns an unsigned int , the i rst byte of data available from the
serial output of the process, or -1 if no data is available. To write serial data to
a process, use write() :
Process.write(val);
Process.write(str);
Process.write(buf, len);
The val parameter sends a single byte to the process. To send data as a String ,
use the str parameter. Finally, you can send data by specifying a char array
as buf and the length of the buffer as len . This function returns a byte , the
number of bytes written to the process.
To l ush the buffer, that is, to delete any data waiting to be read, use flush() :
Process.flush();
This function does not take any parameters and does not return any informa-
tion. It l ushes the incoming buffer after all pending output has been written.
To terminate a process, use close() :
Process.close();
FileIO
The Arduino Yún has an integrated micro-SD slot, allowing users to expand
the i lesystem. This card is handled by Linux, but the FileIO library provides a
convenient way to interact with i les—creating, reading, writing, and deleting.
These functions send instructions through the Arduino Yún bridge.
WARNING
The following functions work only with fi les on the SD card.
Before using i lesystem instructions, you must i rst use begin() :
// Setup File IO
FileSystem.begin();
This function must be called inside setup() . Next, you must create a File
object. To do this, you must open() a i le. If the i le exists, it will be opened. If
the i le does not exist, it will be created, but the folder it is in must exist.
File datafile = FileSystem.open(filename);
File datafile = FileSystem.open(filename, mode);
The filename parameter is a String and indicates the i le to open. It can
include directories so long as they are separated by a forward slash (for example,
"data/log.txt" ). The optional mode parameter indicates how the i le should
be opened, in the default read-only mode (specii ed by FILE_READ ), or in read/
write mode (specii ed by FILE_WRITE ). This function returns a File object and is
 
Search WWH ::




Custom Search