WriteAllText

TwinCAT TIA
Local File and directory access File

ns=2;s=DEPRAG Smart/Local/FileAndDirectoryAccess/FileAccess/WriteAllText

The command writes a string to the specified file.

Parameters:

    FullPath
    Path of the file. The file can be either a local file or a file stored on a network drive.
    Content
    The string to be written to the file.

Returns:

Examples:

In addition to the parameters already explained, the following variables must be created / transferred for the implementation in TwinCAT 3:

Beckhoff parameter:

    bFileAccessWriteAllText
    A boolean variable that can be used to trigger the execution of the WriteAllText command.
    OutputDataFileAccessWriteAllText
    An instance of "ST_VoidOutputData" into which the return value of the WriteAllText method is written.
    hrFileAccessWriteAllText
    This can be used to monitor the execution of the command. Error codes have the type "HRESULT".
    fbFileAccess
    An instance of the "FB_FileAccess" function block supplied with the DEPRAG Smart library.
    sfullPathSourceFile
    A STRING variable containing the full path of the file.
    sTextToWrite
    A STRING variable containing the data to be written.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
     bFileAccessWriteAllText        : BOOL;
     OutputDataFileAccessWriteAllText     : ST_VoidOutputData;
     hrFileAccessWriteAllText       : HRESULT;

     fbFileAccess  : FB_FileAccess;
END_VAR

hrFileAccessWriteAllText := fbFileAccess.WriteAllText(
           bExecute     := bFileAccessWriteAllText,   
           ConnectionHandle  := depragSmartConnection.ConnectionHandle, 
           sfullPathSourceFile  := 'C:\Test\text.txt',
           sTextToWrite   := 'Test123',
           OutputData    => OutputDataFileAccessWriteAllText);
IF hrFileAccessWriteAllText <> S_FALSE THEN 
     bFileAccessWriteAllText := FALSE;
END_IF
                                                    

For examples and explanations regarding the calls of nodes via Siemens TIA Portal please refer to the sub-menu "Siemens TIA Portal" in section "Getting Started".