File Management

File Management functions provide the ability to:

  • Read machine recipes or other machine operational data into the KAS program from the SD card, USB flash drive, or a shared directory.
  • Read cam tables into the program from the SD card, USB flash drive, or a shared directory.
  • Store machine operational data on internal PxMM or PCMM2G flash memory (retrievable through the Web server), the SD card, USB flash drive, or a shared directory.

  • A shared directory connection is setup through the Web server.

    • Functions to parse out information from a file using a string format can be found in String Operations.
    • If the file is in a .CSV format, these functions can be used: LogFileCSV, ApplyRecipeColumn.
    • You can create, store, and retrieve recipes and other data using either:
      • the AKI Terminals. For more information see the KVB manual.
      • an external bus connection to the PxMM or PCMM2G with a supported fieldbus (e.g., UDP or HTTP).

Sequential Read / Write Function Blocks

These function blocks enable sequential read / write operations in disk files:

Name

Description

FileClose

Closes an open file.

FileCopy

Copies a file's contents to a new file.

FileDelete

Removes a file from the file system.

FileEOF

Test if the end of the file is reached in a file that is open for reading.

FileExists

Tests if a file exists.

FileOpenA

Create or open a file in append mode.

FileOpenR

Open a file for reading.

FileOpenW

Create or reset a file and open it for writing.

FileReadBinData

Read binary data from a file.

FileReadLine

Reads a string value from a text file.

FileRename

Renames a file.

FileSeek

Sets the current position in an open file.

FileSize

Gets the size of a file.

FileWriteBinData

Write binary data to a file.

FileWriteLine

Writes a string value to a text file.

SD card Functions

These functions handle mounting of SD cards:

Name

Use

File Management

Verify the SD card is mounted.

File Management

Mount the SD card.

File Management

Unmount the SD card.

Each file is identified in the application by a unique handle manipulated as a DINT value.

  • The file handles are allocated by the target system.
  • Handles are returned by the Open function blocks and used by all other function blocks for identifying the file.

Related Function Blocks

LogFileCSV log values of variables to a CSV file


    • Files are opened and closed directly by the Operating System of the target.
      • Opening some files can be dangerous for system safety and integrity.
      • The number of open files (from FileOpenA, FileOpenR, and FileOpenW) is limited by the resources available on the target system.
    • Verify each file successfully opened using FileOpenA, FileOpenR, and FileOpenW.
      • The FileOpenW has a corresponding FileClose to close the file.
      • Closing the file releases the file ID, making it available for operations on other files.


    • Opening a file with FileOpenA, FileOpenR, and FileOpenW can be unsuccessful (invalid path or file name, too many open files.)
      • Your application must check the file ID for a NULL value.
      • If the file ID is NULL (zero), then file read or write operations will fail.
    • File management may be unavailable on some targets.
    • Memory on the SD card is available in addition to the existing flash memory.
    • Valid paths for storing files depend on the target implementation.
    • Error messages are logged in the Controller log section of KAS Runtime where there is a failure in any related function block.
    • Using the KAS Simulator, all path names are ignored, and files are stored in a reserved directory. Only the file name passed to the Open functions is taken into account.
    • AKD PDMM / PCMM files are big endian.