User Documentation

Table Of Contents
Appendix: Tutorial FoE
System manual
2696790000/02/04.2020
122
21 Appendix: Tutorial FoE
Access via FoE to a device (e.g. to load files onto the device) must be
solved programmatically via the application. In this chapter, a firmware up-
date on a UC20 bus coupler is executed as an example via FoE. The se-
quence of the firmware update is displayed in the message monitor.
Programming block
PROGRAM PRGECatFileTransfer
//Declaration of variables
VAR
//Filetransfer
state: IoApi_State;
err: UDINT;
pass: UDINT;
slavedir: STRING:= '';
masterdir: STRING:= '/home/admin/FB-EC-FULL-0007674-01_08_00-9.bsc';
dir: IoEcat_FileDirection:= IoEcat_FileDirection.download;
mDevHandle: IoApi_Hdl;
//Request "Bootstrap Mode"
 ReqBootStrap: BOOL;
//Leave "Bootstrap Mode"
LeaveBootstrap: BOOL;
//Get Ethercat State
GetState: BOOL;
SlaveState: IoEcat_State;
//State machine
miState: DINT; msState: STRING;
mbLoadNewFW: BOOL;
msFileName: STRING;
msFileDir: STRING;
END_VAR
//Block code
(* Used library: K_IoApi K_SystemCallLibrary Standard
Description:
1. File has to be downloaded to directory "\masterdisk" on control
2. Filename has to be set as value of "msFileName"
3. DeviceHandle of buscoupler has to be set (Property DeviceHandle of Ether-
cat Device)
4. mbLoadNewFW has to be set to TRUE
*)
msFileName:= 'FB-EC-FULL-0007674-01_08_00-9.bsc';
msFileDir:= '/masterdisk/';
mDevHandle:= UR20_FBC_EC.DeviceHandle;
CASE miState OF
0:
IF mbLoadNewFW THEN
mbLoadNewFW:= FALSE;
miState:= 10;
END_IF
10: //Enter Bootstrap
state:= IoApi_EcatEnterBootstrap(devHdl:= mDevHandle);
IoApi_EcatGetState(devHdl:= mDevHandle,pState:= SlaveState);
IF state = IoApi_State.IoApiStateOk AND
SlaveState = IoEcat_State.Bootstrap THEN
msState:= 'Bootstrap entered';