File Functions; File Functions Overview - Crestron SIMPL+ Reference Manual

Language reference guide
Hide thumbs Also See for SIMPL+:
Table of Contents

Advertisement

Software

File Functions

®
116
SIMPL+

File Functions Overview

File Functions perform file handle access from SIMPL+. Because of the overhead
involved with maintaining current directory and file positions, there are restrictions
on file I/O. Each SIMPL+ thread (main loop or event handler) that requires file
operations must first identify itself with the operating system. This is done with the
function, StartFileOperations. Before terminating the thread, the function
EndFileOperations must be called. Files cannot be opened across threads. In other
words, you cannot open a file in one thread (function main say) and then access the
file with the returned file handle in another (say an event handler). This is to prevent
two events from writing to different parts of a file. This means that you should open,
access and then close a file within the same thread. For example, a program might be
structured as follows:
STRING sBuf[1000];
SIGNED_INTEGER nFileHandle;
CHANGE input
{
SIGNED_INTEGER nNumRead;
StartFileOperations();
nFileHandle = FileOpen ( "\\CF0\\MyFile", _O_RDONLY );
if ( nFileHandle >= 0 )
{
nNumRead=FileRead( nFileHandle, sBuf, 500 );
if(nNumRead<0)
Print ("Read Error\n");
FileClose( nFileHandle );
}
EndFileOperations();
}
/******************************************************
Main()
Uncomment and place one-time startup code here
(This code will get called when the system starts up)
******************************************************/
Function Main()
{
SIGNED_INTEGER nNumWritten;
StartFileOperations();
nFileHandle = FileOpen ( "\\CF0\\MyFile", _O_WRONLY );
if ( nFileHandle >= 0 )
{
sBuf = "Hello World!";
nNumWritten=FileWrite( nFileHandle, sBuf, 500 );
Crestron SIMPL+
Language Reference Guide - DOC. 5797G
®

Advertisement

Table of Contents
loading

Table of Contents