Reading And Writing Data - Crestron SIMPL+ Programming Manual

Crestron simpl+ software: software guide
Hide thumbs Also See for SIMPL+:
Table of Contents

Advertisement

Software
40 • SIMPL+
flash card within the control system. The function will return an error code and the
program can act accordingly.
Other programs might prompt the end-user to insert a compact flash card. The
function, WaitForNewDisk, will halt the program and resume when a compact flash
card is detected within the control system.
The following is an example of a program that needs to read data from a compact
flash card upon startup:
FUNCTION ReadMyCompactFlashCard()
{
// call functions to read the compact flash card
//
// Note that this function will exist within the same
//
thread as the calling function (Function Main).
//
Because of this, the functions, StartFileOperations
//
and EndFileOperations should not be used here.
}
Function Main()
{
StartFileOperations();
if (CheckForDisk() = 1)
Call ReadMyCompactFlashCard();
else if ( WaitForNewDisk() = 0 )
Call ReadMyCompactFlashCard();
EndFileOperations();
}
If the program is dependent upon data that read in from the compact flash card, it is
imperative for the program to validate the existence of the card. Otherwise, the
program will not have the necessary data needed to execute properly. The above
function will first check if the compact flash card is already inserted into the control
system upon system startup. If so, it will call the user-defined function,
ReadMyCompactFlashCard, to perform any file read operations on the compact
flash card. If the compact flash card was not found in the control system, the
program will wait for the card to be inserted before continuing. Once inserted, the
same function, ReadMyCompactFlashCard, is called.

Reading and Writing Data

Once the existence of the compact flash card is verified, the reading and writing of
data can be performed. Data can be read or written either with individual elements
(i.e., a single integer or string), or with entire structures of data.
Because each datatype (i.e.: INTEGER, STRING, LONG_INTEGER) uses a
different amount of storage in memory, there are different functions to read and write
each of these types. The return value of each of these functions is the actual number
of bytes read or written to the file. The reason why different functions have to be
called instead of having just one function is for the following reason. Data elements
are written to a file by inserting one element after another. The file does not contain
any information as to what that data is or how it is to be extracted out. It is up to the
program that will ultimately read that file to know exactly what is contained within
the file and how to extract the data back out of it.
The following example demonstrates this:
Crestron SIMPL+
Programming Guide – DOC. 5789A

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents