FB_EcFoeWriteFile

FB_EcFoeWriteFile 1:

The function block FB_EcFoeWriteFile can be used to write files from a local data carrier to an EtherCAT device via the "File access over EtherCAT" mailbox protocol.

FB_EcFoeWriteFile 2:

The file path can only point to the local file system on the computer. This means that network paths cannot be used here.

FB_EcFoeWriteFile 3: Inputs

VAR_INPUT
    sFSrvNetId     : T_AmsNetId := '';
    sFSrvPathName  : T_MaxString;
    sEcNetId       : T_AmsNetId;
    nSlaveAddr     : UINT;     
    sFoEPathName   : T_MaxString;
    dwPass         : DWORD := 0;
    bExecute       : BOOL; 
    tTimeout       : TIME := T#200s; 
END_VAR

Name

Type

Description

sFSrvNetId

T_AmsNetId

AMS network ID of the computer from which the file to be written is to be read. (Default: local computer)

sFSrvPathName

T_MaxString

Contains the path and filename of the file to be read (e.g.: 'C:\Data\LogData.csv').

sEcNetId

T_AmsNetId

String containing the AMS network ID of the EtherCAT master device.

nSlaveAddr

UINT

Address of the EtherCAT slave

sFoEPathName

T_MaxString

Name of the file on the EtherCAT slave (e.g. 'LogData')

dwPass

DWORD

Password

bExecute

BOOL

The function block is activated by a positive edge at this input.

tTimeout

TIME

Maximum time allowed for the execution of the function block. (Default: 200 s.)

FB_EcFoeWriteFile 4: Outputs

VAR_OUTPUT
    bBusy     : BOOL;
    bError    : BOOL;
    nErrId    : UDINT;
    cbWritten : UDINT;
    nProgress : UDINT;
    sInfo     : T_MaxString;
END_VAR

Name

Type

Description

bBusy

BOOL

This output is set when the function block is activated, and remains set until a feedback is received.

bError

BOOL

This output is set after the bBusy output has been reset when an error occurs in the transmission of the command.

nErrId

UDINT

Supplies the ADS error code associated with the most recently executed command if the bError output is set.

cbWritten

UDINT

Number of successfully written data bytes

nProgress

UDINT

Write access progress (range: 0 - 100%).

sInfo

T_MaxString

Additional FoE error information (reserved)

Sample in ST:

A rising edge at the bExecute variable triggers writing of the specified file via the "File access over EtherCAT" mailbox protocol. The file named in sFSrvPathName is read from the selected computer (sFSrvNetID). The file is stored on the selected EtherCAT slave (sEcNetId & nSlaveAddr) under the name specified in sFoEPathName. If a password is required for writing the file to the EtherCAT slave, this can be specified via dwPass.

The read and write operation is not completed until bBusy switches to FALSE. Only then can the error information or the number of bytes read be evaluated.

PROGRAM MAIN
VAR
    fbEcWriteFile : FB_EcFoeWriteFile := (
        sFSrvNetID     := '5.0.34.38.1.1', (* NetID for source file *)
        sFSrvPathName  := 'C:\Data\LogData.csv', (* Pathname for source file *)
        sEcNetId       := '5.0.34.38.3.1', (* NetID of EtherCAT master *)
        nSlaveAddr     := 1004, (* EtherCAT slave address *)
        sFoEPathName   := 'LogData', (* Name of target file *)
        dwPass         := 0
    );
    bExecute   : BOOL := TRUE;
    bBusy      : BOOL;
    bError     : BOOL;
    nErrID     : UDINT;
    nBytesWritten : UDINT;
END_VAR

fbEcWriteFile (
        bExecute := bExecute,
        bBusy => bBusy,
        bError => bError,
        nErrId => nErrID
);
IF NOT bBusy THEN
    bExecute := FALSE;

    IF NOT bError THEN
         (* done, no error *)
        nBytesWritten := fbEcWriteFile.cbWritten;
    ELSE
        (* evaluate error *)
        nBytesWritten := 0;
    END_IF
    fbEcWriteFile (bExecute := FALSE);
END_IF

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4024.56

PC or CX (x86, x64, ARM)

Tc2_EtherCAT >= 3.5.1.0