FB_EcFoeReadFile

FB_EcFoeReadFile 1:

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

FB_EcFoeReadFile 2:

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

FB_EcFoeReadFile 3: Inputs

VAR_INPUT
    sFSrvNetId     : T_AmsNetId DWORD := '';
    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 DWORD

AMS network ID of the computer on which the file that was read is to be written (local computer). (Type: T_AmsNetId)

sFSrvPathName

T_MaxString

Contains the path and file name of the file to be written (e.g.: 'C:\Data\LogData.csv'), (type: T_MaxString).

sEcNetId

T_AmsNetId

String containing the AMS network ID of the EtherCAT master device. (Type: T_AmsNetId)

nSlaveAddr

UINT

Address of the EtherCAT slave (type: UINT)

sFoEPathName

T_MaxString

Name of the file on the EtherCAT slave, e.g. 'LogData' (type: T_MaxString)

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_EcFoeReadFile 4: Outputs

VAR_OUTPUT
    bBusy     : BOOL;
    bError    : BOOL;
    nErrId    : UDINT;
    cbRead    : 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.

cbRead

UDINT

Number of successfully read data bytes

sInfo

T_MaxString

Additional FoE error information (reserved)

Sample in ST:

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

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

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

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

    IF NOT bError THEN
         (* done, no error *)
        nBytesRead := fbEcReadFile.cbRead;
    ELSE
        (* evaluate error *)
        nBytesRead := 0;
    END_IF
    fbEcReadFile (bExecute := FALSE);
END_IF

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_EtherCAT >= 3.3.14