ReadAllText

TwinCAT TIA
Local File and directory access File

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

The command reads the contents of a file into a string.

Parameters:

    FullPath
    Path of the file. The file can be either a local file or a file stored on a network drive.
    Encoding
    The encoding of the contents of the file.

Returns:

    ReadAllText
    A variable of type OpcMethodReturnValueString. The Result property contains the command-specific return values.
      Result
      The contents of the file as a string.

Examples:

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

Beckhoff parameter:

    bFileAccessReadAllText
    A boolean variable that can be used to trigger the execution of the ReadAllText command.
    OutputDataFileAccessReadAllText
    An instance of "ST_ReadAllTextOutputData" to which the return value of the ReadAllText method is written.
    hrFileAccessReadAllText
    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.
    Encoding
    An enumeration of type Encoding, which contains the encoding of the contents of the file.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
     bFileAccessReadAllText        : BOOL;
     OutputDataFileAccessReadAllText      : ST_ReadAllTextOutputData;
     hrFileAccessReadAllText        : HRESULT;

     fbFileAccess  : FB_FileAccess;
END_VAR

hrFileAccessReadAllText := fbFileAccess.ReadAllText(
           bExecute     := bFileAccessReadAllText,   
           ConnectionHandle  := depragSmartConnection.ConnectionHandle, 
           sfullPathSourceFile  := 'C:\Test\text.txt',
           Encoding    := Encoding.Utf8,
           OutputData    => OutputDataFileAccessReadAllText);
IF hrFileAccessReadAllText <> S_FALSE THEN 
     bFileAccessReadAllText := 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".