Function Description

The CREATE_FILE function enables creation of a file called FILENAME, if it doesn’t exist, and allows it to be opened with the specified ModeFlag flag:

  • O_RDONLY: opening in read-only mode (value 0),

  • O_WRONLY: opening in write-only mode (value 1),

  • O_RDWR: opening in read and write mode (value 2),

This flag is reset to 0 once the file is closed.

The file is created in the \DataStorage\. sub-directory

If you use the simulator mode the file is created in the temporary user folder.

To access the file by FTP refer to this page.

NOTE: Each time a file is opened, a random value is returned by the FileDescriptor parameter.

This will be used when you close the file. If you open a new file without closing the previous one, a new FileDescriptor parameter value is returned, and you will not be able to close the previous file.Therefore you should save the FileDescriptor parameter after opening a file.

When the maximum number of opened files is reached, an error is returned if you try to open any further files.

NOTE: If the file already exists, the behavior of CREATE_FILE is similar to that of OPEN_FILE.

The additional parameters EN and ENO can be configured.

FBD Representation

The representation in FBD of the CREATE_FILE function is as follows:

Ladder Representation

The representation in Ladder of the CREATE_FILE function is as follows:

IL representation

Representation:

CAL CREATE_FILE_Instance (REQ:=CreateFileStart, SLOT:=CreateFileSlot, FILENAME:=CreateFileName, MODEFLAG:=CreateFileModeFlag, DONE=>CreateFileDone, ERROR=>CreateFileError, STATUS=>CreateFileStatus, FILEDESC=>CreateFileDescriptor)

ST representation

Representation:

CREATE_FILE_Instance (REQ:=CreateFileStart, SLOT:=CreateFileSlot, FILENAME:=CreateFileName, MODEFLAG:=CreateFileModeFlag, DONE=>CreateFileDone, ERROR=>CreateFileError, STATUS=>CreateFileStatus, FILEDESC=>CreateFileDescriptor);

Parameter Description

The following table describes the input parameters:

Parameter

Type

Comment

SLOT

DINT

This parameter specifies the slot address of the memory card (always has address 0).

FILENAME

STRING

This parameter specifies the name of the file to create.

Maximum number of characters : 64

Characters like ‘ ?’ or ‘ * ‘ are not allowed.

MODEFLAG

INT

This parameter specifies the opening mode.

  • O_RDONLY (0): opened in read-only mode,

  • O_WRONLY (1): opened in write-only mode,

  • O_RDWR (2): opened in read and write mode.

The following table describes the output parameters:

Parameter

Type

Comment

FILEDESC

DINT

This parameter allows the DATA_STORAGE function to access the file.

Description of common parameters.