WriteAllBytes

TwinCAT TIA
Local File and directory access File

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

The command writes a byte array to a file.

Parameters:

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

Returns:

Examples:

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

Beckhoff parameter:

    bFileAccessWriteAllBytes
    A boolean variable that can be used to trigger the execution of the WriteAllBytes command.
    OutputDataFileAccessWriteAllBytes
    An instance of "ST_VoidOutputData" in which the return value of the WriteAllBytes method is written.
    hrFileAccessWriteAllBytes
    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.
    BytesToWrite
    A byte array containing the data to be written.
    nNumberOfBytesToWrite
    A UINT variable containing the number of bytes to be written.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
     bFileAccessWriteAllBytes       : BOOL;
     OutputDataFileAccessWriteAllBytes     : ST_VoidOutputData;
     hrFileAccessWriteAllBytes       : HRESULT;

     fbFileAccess  : FB_FileAccess;
END_VAR

hrFileAccessWriteAllBytes := fbFileAccess.WriteAllBytes(
           bExecute     := bFileAccessWriteAllBytes,   
           ConnectionHandle  := depragSmartConnection.ConnectionHandle, 
           sfullPathSourceFile  := 'C:\Test\text.txt',
           BytesToWrite   := testShortByteArray,
           nNumberOfBytesToWrite := 4,
           OutputData    => OutputDataFileAccessWriteAllBytes);
IF hrFileAccessWriteAllBytes <> S_FALSE THEN 
     bFileAccessWriteAllBytes := 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".