Download project
This example shows several possibilities of writing and reading files as well as working with directories.
Synchronous and asynchronous function calls are used.
Several functions for file management are demonstrated here, such as creating files and directories,
renaming, deleting and copying them as well as reading and writing files.
A directory can be browsed to find all included files.
In the synchronous way, the function will wait until a result is returned. Sometimes this lasts longer
than one cycle. There for an asynchronous call can be used. Here the function will not wait for a result.
At each call the function will ask again for a result, when it is available the variable xDone
is set
to true, otherwise it stays false until a result is available.
SystemDir
: Several synchronous functions are used to create a directory.
The directory is browsed to find all included files. After renaming, the directory will be deleted.
SystemFile
: Several synchronous functions for file modification are used.
First the file is opened with write access. A string is written to the file and it will be closed after.
The next step opens the file again and reads the written string. After copying the file a new string is
appended at the end. Some file information like creation time and size are retrieved as well.
CAA_Dir
: It shows how to create, open, close rename, browse and remove a directory. This is done in an
asynchronous way with use of a state machine. When the function block is done or sends an error,
the Next
or Error
state is reached.
CAA_File
: This program does some file modification in an asynchronous way. After opening the file
a string is written into that file and later read again. File information are fetched as well as appending
another string into the file.
A function can be executed via visualization.
System requirements and restrictions | Info |
---|---|
Programming System | CODESYS Development System Version 3.5.14.0 or higher |
Runtime System | CODESYS Control Version 3.5.14.0 |
Required Accessories | - |