FP_FTP_SET_MODE

Set FTP transfer mode

This FP instruction stores the FTP client transfer settings of sOperation, sPLCFullFileNameOrDataFormat and sFTPServerFullFileName in the transfer setting area specified by nTransferID.

Parameters

Input

nTransferID (WORD, INT, UINT)

Set the transfer setting ID.

Values: 0–15 (values must be entered in ascending order)

sOperation (STRING)

Set the transfer method parameters.

  • Server address (required parameter)

    Keyword: SV

    Syntax: 'SVx'

    Values: SV0–SV3 (Server 0–Server 3)

  • Transfer target and method (required parameter)

    Parameter string

    Target

    Transfer method

    PUTFILE

    File

    Send to servers (Overwrite method)

    PUTFILE-OVW

    Send to servers (Overwrite method)

    PUTFILE-REN

    Send to servers (Rename method)

    GETFILE

    Obtain from servers

    PUTDATA

    Memory area

    Send to servers (Overwrite method)

    PUTDATA-OVW

    Send to servers (Overwrite method)

    PUTDATA-REN

    Send to servers (Rename method)

    GETDATA

    Obtain from servers

  • File handling after transfer (required parameter)

    • DEL: delete the file

    • NON: do not delete the file

Examples:
  1. Send file to FTP server 1 using overwrite method, do not delete file after transfer: 'SV1,PUTFILE-OVW,NON'

  2. Send file to FTP server 0 using rename method, delete file after transfer: 'SV0,PUTFILE-REN,DEL'

  3. Get file from FTP server 2, delete file after transfer: 'SV2,GETFILE,DEL'

sPLCFullFileNameOrDataFormat (STRING)

Make the settings according to your transfer target (file or data from memory area) and the transfer method (PUT or GET).

Transfering data of a variable can be done by using the instruction FP_FTP_GET_DATA_FORMAT. The output of that instruction will be connected to sPLCFullFileNameOrDataFormat to read the string specifying the data format string of the variable (memory area, size, and data type). The transmitted data is written to or read from a CSV file according to the data type of the variable.

  • Transfer target: file

    Set the source file name.

    • For PUTFILE: Specify the file name of a file stored on an SD card with a relative path. Example: '\LOG\MyData.csv'

    • For GETFILE: Specify a file name from the home directory of a user which logs in FTP servers with a relative path. Example: '\LOG\MyData.csv'

  • Transfer target: data from memory area

    • For PUTDATA: The data stored in the variable connected to input of FP_FTP_GET_DATA_FORMAT is written into the CSV file specified by sFTPServerFullFileName. For this transfer method, it is possible to add a time stamp in the format yymmdd_hhmmss to the file name. Use the keywords 'TOP' and 'END' to specify whether to add the time stamp before or after the file name.

    • For GETDATA: The data of the CSV file specified by sFTPServerFullFileName is written into the variable connected to the input Var of FP_FTP_GET_DATA_FORMAT.

sFTPServerFullFileName (STRING)

Make the settings according to your transfer target (file or data from memory area) and the transfer method (PUT or GET).

  • Transfer target: file

    • For PUTFILE: Specify a folder name with its relative path from the home directory of the user who logs in to the FTP server. For specifying the home directory, specify "/" or “\" only.

    • For GETFILE: Specify a storage folder name in an SD card with an relative path.

  • Transfer target: data from memory area

    • For PUTDATA: Specify a destination CSV file name to write data into. For this transfer method, it is possible to add a time stamp in the format yymmdd_hhmmss to the file name. Use the keywords 'TOP' and 'END' to specify whether to add the time stamp before or after the file name.

      Examples:

      1. Transfer data to the destination file "PutData1.bin" located in the directory "\FTP", do not add a time stamp: '\FTP\PutData1.bin'

      2. Transfer data to the destination file "PutData2.bin" located in the directory "\FTP", add a time stamp at the beginning of the file name: '\FTP\PutData2.bin,TOP'

      3. Transfer data to the destination file "PutData3.bin" located in the directory "\FTP", add a time stamp at the end of the file name: '\FTP\PutData3.bin,END'

    • For GETDATA: Specify a source CSV file name to read data from. Specify a file name and a folder name with its relative path from the home directory of the user who logs in to the FTP server.

Output

bError (BOOL)

Turns to TRUE under the following conditions:

  • if a timeout of the connection is exceeded

  • if an IP address is invalid

When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.

Remarks

  • The number of characters for string data must not exceed 256.

  • This instruction is not available in interrupt programs.

  • Before you execute the instruction, you need to specify the FTP server using FP_FTP_SET_CONNECTION or the setting dialog of the FTP client.

  • Before you execute the instruction, make sure that sys_bIsEthernetInitializing is FALSE. sys_bIsEthernetInitializing turns to TRUE when the instruction is executed. When you execute the instruction while sys_bIsEthernetInitializing is TRUE, an error occurs.

  • The instruction can only be executed when the transfer request flag for the specified transfer setting or the specified nLogID number is FALSE. When the transfer request flag is TRUE, an operation error occurs.

  • When this instruction has been executed successfully, the system variables sys_bIsCarry and sys_iEthernetConnectionErrorCode are reset.

  • After the FTP client transfer settings have been completed, data is sent to files or obtained from files when FP_FTP_TRANSFER_REQUEST is executed.

  • When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if a value specified for a parameter is outside the permissible range.

  • if transfer IDs are not specified in ascending order.

  • if the instruction is executed in an interrupt program

  • if the number of characters for string data exceeds 256.

  • if an FTP server that has not been configured with the instruction FP_FTP_SET_CONNECTION or the setting dialog of the FTP client is specified.

  • if the transfer request flag for the specified transfer setting is "TRUE: Transfer requested" when the instruction is executed.

  • if the transfer request flag for a specified nLogID number is TRUE, e.g. if sys_blsLog0DataRecordingActive is TRUE.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if a value specified for a parameter is outside the permissible range.

  • if transfer IDs are not specified in ascending order.

  • if the instruction is executed in an interrupt program

  • if the number of characters for string data exceeds 256.

  • if an FTP server that has not been configured with the instruction FP_FTP_SET_CONNECTION or the setting dialog of the FTP client is specified.

  • if the transfer request flag for the specified transfer setting is "TRUE: Transfer requested" when the instruction is executed.

  • if the transfer request flag for a specified nLogID number is TRUE, e.g. if sys_blsLog0DataRecordingActive is TRUE.

sys_bIsCarry (turns to TRUE for one scan)
  • if the instruction is executed during the initialization of Ethernet, sys_iEthernetConnectionErrorCode is set to "11: Ethernet is being initialized".

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		bSetModeFileError: BOOL:=FALSE;
		bSetModeFileOK: BOOL:=FALSE;
		iID10: INT:=10;
		bSetModeFile: BOOL:=FALSE;
		wErrorCode: WORD:=0;
	END_VAR

POU body

If bSetModeFile changes from FALSE to TRUE and sys_bIsEthernetInitializing is FALSE, the instruction is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_COMMENT,, ^Set mode to transfer file located on SD card of FP7 PLC,4,1,34,4,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_CONTACT,,bSetModeFile,5,1,7,3,R);
B(B_VARIN,,'SV0~PUTDATA-OVW~NON',23,3,25,5,);
B(B_VARIN,,'\CSV_FILES\Data1.csv',23,4,25,6,);
B(B_VAROUT,,bSetModeFileError,43,2,45,4,);
B(B_VARIN,,'\B:\LOG\MyData.csv~END',23,5,25,7,);
B(B_VARIN,,iID10,23,2,25,4,);
B(B_CONTACT,,sys_bIsEthernetInitializing,16,1,18,3,N);
B(B_F,FP_FTP_SET_MODE!,,25,0,41,7,,?DEN?DnTransferID?DsOperation?DsPLCFullFileNameOrDataFormat?DsFTPServerFullFileName?AENO?CbError);
L(1,2,5,2);
L(7,2,16,2);
L(18,2,25,2);
L(1,0,1,7);
L(41,3,43,3);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 4 ;
        NETWORK_BODY
B(B_CONTACT,,bSetModeFileError,5,1,7,3,);
B(B_F,E_MOVE!,,25,0,31,4,,?DEN?D?AENO?C);
B(B_VARIN,,sys_iEthernetConnectionErrorCode,23,2,25,4,);
B(B_VAROUT,,wErrorCode,31,2,33,4,);
L(7,2,25,2);
L(1,2,5,2);
L(1,0,1,4);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 3 ;
        NETWORK_BODY
B(B_CONTACT,,bSetModeFileError,5,1,7,3,N);
B(B_COIL,,bSetModeFileOK,28,1,30,3,);
L(7,2,28,2);
L(1,2,5,2);
L(1,0,1,3);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

If DF(bSetModeFile) AND NOT sys_bIsEthernetInitializing then
    FP_FTP_SET_MODE(nTransferID := iID10,
                    sOperation := 'SV0,PUTDATA-OVW,NON',
                    sPLCFullFileNameOrDataFormat := FP_FTP_GET_DATA_FORMAT(Var := arrayValues,
                                                    nSize := Size_Of_Var(arrayValues),
                                                    nColumns := 8), 
                                                    sFTPServerFullFileName := '\B:\LOG\MyData.csv,END',
                                                    bError => bSetModePlcDataError);
End_if;
If (bSetModePlcDataError) then
    wErrorCode := sys_iEthernetConnectionErrorCode;
Else
    bSetModePlcDataOK := True;
End_If;

Modified on: 2024-03-06Feedback on this pagePanasonic hotline