Function Block FS_WRITE

The function block FS_WRITE writes data to a file system.

Warning: Existing files are overwritten without warning.

The file system must have been initialized beforehand using FS_INIT. All operations are performed asynchronously per configured storage medium.

Input WRITE

A positive edge triggers the data to be written to the storage medium.

Input DEV

Defines the device from which files should be accessed. The device is used per project and can be managed in the context menu under Project External Storage.

Input PATH

Specifies the path to the file on the storage medium. The path corresponds to a Unix file path in UTF-8 format, if this is supported. The path is represented as follows:

Folder/Subfolder/File.txt

Input DATA

Defines the data that should be written.

Input MODE

Specifies the mode in which the file should be written. Possible modes are:

Mode Description
"r" Opened for reading only. Places the file pointer at the beginning of the file.
"r+" Opened for reading and writing. Places the file pointer at the beginning of the file.
"w" Opened for writing only. Places the file pointer at the beginning of the file. Deletes the content of the file. If the file does not exist, it is created.
"w+" Opened for writing and reading. Places the file pointer at the beginning of the file. Deletes the content of the file. If the file does not exist, it is created.
"a" Opened for writing only. Places the file pointer at the end of the file. If the file does not exist, it is created. The data is appended.
"a+" Opened for writing and reading. Places the file pointer at the end of the file. If the file does not exist, it is created. The data is appended.
"x" Opened for writing only. Places the file pointer at the beginning of the file. If the file exists, it is aborted.
"x+" Opened for writing and reading. Places the file pointer at the beginning of the file. If the file exists, it is aborted.
"c" Opened for writing only. Places the file pointer at the beginning of the file. If the file does not exist, it is created. Overwrites the content of the file.
"c+" Opened for writing and reading. Places the file pointer at the beginning of the file. If the file does not exist, it is created. Overwrites the content of the file.

Input BOM

If the input is true when writing, the UTF-8 Byte Order Mark is appended at the beginning of the file. This only happens if the file is overwritten or created new. If the BOM was not written at the beginning of the file, it cannot be added later.

Output DONE

The output returns a pulse upon success to perform the next operation. The pulse occurs when the process ends, even if an error has occurred.

Output LENGTH

Returns the number of bytes written. The state is stored for later use.

Output ERROR

In case of an error, returns a text with an error message. This is FALSE if no error has occurred. The state is stored for later use.

Possible causes:

  • The storage medium service was not started.
  • The memory was not initialized.
  • The login credentials are invalid.
  • The remote server could not be reached.
  • The storage medium does not exist.
  • The specified path is invalid.
  • Cannot write to the storage medium.
  • No more storage space available on the memory or the memory is write-protected.