Input Action: File Transfer Permalink

With the “File Transfer” input action, a file can be transferred from an operating variant (target or web visualization) to the PLC as well as to and from the PLC. This works either by means of a file transfer (“Type”: “File”) or streaming (“Type”: “Streaming”).

The action has the effect that a file selection dialog is displayed in the visualization at runtime. There the visualization user can select a file which will be transferred either to or from the PLC: For a transfer from a PLC to the visualization, the “Save File” dialog opens. For the transfer from the visualization to the PLC, the “Open File” dialog opens.

“Transfer”

“Direction”

Direction of file transfer

“From PLC to Visualization”

The object specified in “File name” or “Streaming instance name” is transferred from the PLC to the visualization.

The “Save File” file selection dialog is displayed in the visualization at runtime.

“From Visualization to PLC”

The file specified by the visualization user is transferred to the PLC and saved in the file path specified in “File name” or “Streaming instance name”.

The “Open File” file selection dialog is displayed in the visualization at runtime.

“Type”

Determines how the file is transferred

  • Transfer type “File”: By file transfer

  • Transfer type “Streaming”: By streaming

“Type”

“File”

The data transfer is done by file transfer.

“File name”

File path (type ‎STRING‎) which describes the file in the file system

  • Variable

    Example: ‎strTransferFile: STRING;‎

  • Literal with relative path

    Example: ‎'/Recipes/Recipe_1.txt'‎ saves the file in the directory ‎Recipes‎.

  • Literal with placeholder ‎$PLCLOGIC$‎

    ‎PlcLogic‎ is the default resolution for the directory placeholder ‎$PLCLOGIC$‎.

    Example: ‎'$$PLCLOGIC$$/test.txt'‎ saves the file in the directory ‎PlcLogic‎.

    Example: ‎'$$PLCLOGIC$$/MyData/test.txt'‎ saves the file in the directory ‎PlcLogic/MyData‎.

  • Literal with placeholder ‎$VISU$‎

    ‎visu‎ is the default resolution for the placeholder ‎$VISU$‎.

    Example: ‎'$$VISU$$/test.txt'‎ save the file in the subdirectory ‎PlcLogic/visu‎. Alternatively, ‎'visu/test.txt'‎ can also be specified.

  • Literal with absolute path

    Example: ‎'E:\temp\test.txt'‎

    Note: These kinds of file paths are not always supported.

NOTE:

If a user specifies the file path in the visualization by means of a “Text Field” element, the masking character ‎$‎ must not be included: ‎$VISU$/dummy.txt‎

NOTE:

In the case that the file path is specified by the user, it should be checked by the application in order to prevent files from being read or overwritten accidentally.

“Type”

“Streaming”

The data transfer is done by streaming.

“Streaming instance name”

Instance path (type ‎IVisuStreamWriter‎ or ‎IVisuStreamReader‎) which describes the object in the file system of the controller

Type ‎IVisuStreamReader‎ for transfer direction “From PLC to Visualization”

Type ‎IVisuStreamWriter‎ for transfer direction “From Visualization to PLC”

“Control flags”

Note: The variable is evaluated only for transfer direction “From Visualization to PLC”.

Variable (type ‎DWORD‎)

Determines how the object (file or instance object) is handled on the file system of the PLC. Two flags are provided for this with which the variable can be set.

  • Flag 1: ‎VisuElems.VisuEnumFileTransferControlFlags.UseOriginalFileName‎

  • Flag 2: ‎VisuElems.VisuEnumFileTransferControlFlags.ConfirmFileOverwriteInPlc‎

Options

  • No flag set:

    The user selects a file which is saved in the path specified in “File name” or “Streaming instance name”.

  • Flag 1 is set:

    The path, which is specified by the user at visualization runtime, is applied and used as the path in the PLC file system.

  • Both flags are set:

    The path is also checked. If an object already exists in the path specified on the client side, then a message prompt is displayed in the visualization. There the visualization user can confirm that the file will be overwritten.

Example: ‎dwControlFlag‎

Example

The transfer direction is “From Visualization to PLC” (write).

Example: A new recipe file ‎Recipes/Recipe_2021.txt‎ has been created in the visualization device. The visualization user selects this file and wants to save the file on the PLC under the same name. Because the control flags are set accordingly, a message window opens and the visualization user can confirm that the file will be overwritten.

PROGRAM PLC_PRG
VAR
    xVisuToggle : BOOL;
    dwControlFlag : DWORD := VisuElems.VisuEnumFileTransferControlFlags.UseOriginalFileName
                             + VisuElems.VisuEnumFileTransferControlFlags.ConfirmFileOverwriteInPlc;
    strFileName: STRING := '/Recipes/Recipe_new.txt';
END_VAR

“Status Variables”

“Transfer active”

Boolean variable (optional)

‎TRUE‎: The transfer is in progress.

“Transfer successful”

Boolean variable (optional)

‎TRUE‎: The transfer has completed successfully.

“Error code”

  • ‎0‎: No errors

  • ‎1‎: Unspecified error

  • ‎2‎: Cancellation of file dialog

  • ‎3‎: Other file transfer in progress

  • ‎4‎: Error during file transfer

  • ‎5‎: Cancellation by timeout

  • ‎6‎: File read error – The file is not available or cannot be read.

  • ‎7‎: No device support for file transfer

    Possible causes:

  • CODESYS WebVisu: File transfer is not possible by default.

  • Communication with a controller of a version < 3.5.11: Functionality not implemented.

  • Communication with a controller of a version >= 3.5.11: File transfer not activated (device description).

    TIP:

    CODESYS manages this setting in the project settings.

“Use local visualization files”

Requirement: The option is available when “Transfer visualization files to the PLC” has been specified as the direction.

  • _cds_icon_option_deactivated.png: The file selection dialog of the operating system is immediately displayed (default for a recently created input action).

  • _cds_icon_option_black_activated.png: The file transfer dialog, which is available by default, opens and prompts you to select a file. You can adapt the dialog.

    Hint: It is possible that the dialog is displayed in an inconvenient location and that the dialog layout does not correspond to that of the interface of the web visualization.