This demo describes how to access files via the TwinCAT "ITCFileAccess" Interface. The access is synchronous and could for example be used to read configuration upon startup of a module.
The sample contains one C++ Module “TcFileTestDrv” with an instance of that module “TcFileTestDrv_Obj1”.
Within this example file access is done in the “PREOP to SAFEOP” transition, thus within the "SetObjStatePS()" method.
Helper methods encapsulate the file handling itself.
As demonstration first general file-information and a directory listing is printed to the logging facility of TwinCAT 3. Afterwards a file “%TC_TARGETPATH%DefaultConfig.xml” (usually “C:TwinCAT3.xTargetDefaultConfig.xml”) is copied to "%TC_TARGETPATH%DefaultConfig.xml.bak"
For accessing the log entries, please see the tab “Error List” of the Output window of TwinCAT 3.
You could adjust the verbosity by changing the TraceLevelMax variable at the instance “TcFileTestDrv_obj1” within the tab “Parameter (Init)”.