6.12. File access over EtherCAT (FoE)

The File access over EtherCAT (FoE) mailbox command specifies a standard way to download a firmware or any other files from a client to a server or to upload a firmware or any other files from a server to a client.

Reference:

  • ETG.1000.5 and ETG.1000.6

6.12.1. Specification

6.12.1.1. FoE file download

Regular download

skinparam monochrome true
skinparam SequenceMessageAlign direction
hide footbox

Master -> Slave: WRQ (file name)
Master <- Slave: ACK (packet no 0)
Master -> Slave: WRQ (packet no 1, full mailbox)
Master <- Slave: ACK (packet no 1)
Master -> Slave: WRQ (packet no 2, full mailbox)
Master <- Slave: ACK (packet no 2)
Master -> Slave: WRQ (packet no 3, less data or zero data)
Master <- Slave: ACK (packet no 3)

Segmented download

In case of segmented download the EC-Master raises emNotify - EC_NOTIFY_MBOXRCV in EC-Master Class B documentation to request more data from the application after each ACK from the slave. The notification handler may not block the EC-Master, e.g. due to reading from or writing to the file system, therefore applications typically do not handle EC_NOTIFY_MBOXRCV within the JobTask context. The segments are transferred using the slave’s mailbox, so the maximum size of a segment is known from the configuration. The segment’s size can be calculated as follows:

segment size = mailbox size - 12 (protocol overhead)

Download with busy

skinparam monochrome true
skinparam SequenceMessageAlign direction
hide footbox

Master -> Slave: WRQ (file name)
Master <- Slave: ACK (packet no 0)
Master -> Slave: DATA (packet no 1, full mailbox)
Master <- Slave: ACK (packet no 1)
Master -> Slave: DATA (packet no 2, less data or zero data)
Master <- Slave: BUSY (X of N done)
Master -> Slave: DATA (packet no 2, less data or zero data)
Master <- Slave: ACK (packet no 2)

Download with error

skinparam monochrome true
skinparam SequenceMessageAlign direction
hide footbox

Master -> Slave: WRQ (with file name)
Master <- Slave: ERR (error code and optional error text)

6.12.1.2. FoE file upload

The names of availables files and their size are slave specific and cannot be retrieved using FoE. It is possible to upload the complete file in segments without the need to know the file size.

The segments are transferred using the slave’s mailbox, so the maximum size of a segment is known from the configuration.

Regular upload

skinparam monochrome true
skinparam SequenceMessageAlign direction
hide footbox

Master -> Slave: RRQ (file name)
Master <- Slave: DATA (packet no 1, full mailbox)
Master -> Slave: ACK (packet no 1)
Master <- Slave: DATA (packet no 2, full mailbox)
Master -> Slave: ACK (packet no 2)
Master <- Slave: DATA (packet no 3, less data or zero data)
Master -> Slave: ACK (packet no 3)

6.12.1.3. Boot State

For the download of firmware the BOOT state in the EtherCAT state machine is defined. In bootstrap mode only FoE Download is possible. A special Mailbox size can be supported by the slave for the Boot state (ETG.2000). This is part of the Init-Commands in the network configuration.

6.12.2. emFoeFileDownload

static EC_T_DWORD ecatFoeFileDownload(EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_BYTE *pbyData, EC_T_DWORD dwDataLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)
EC_T_DWORD emFoeFileDownload(EC_T_DWORD dwInstanceID, EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_BYTE *pbyData, EC_T_DWORD dwDataLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)

Execute a FoE File download to an EtherCAT slave device.

This function is used to download a complete file. The function returns after the download has been successfully completed or an error has occurred. This function may not be called from within the JobTask’s context.

Parameters
  • dwInstanceID – [in] Instance ID (Multiple EtherCAT Network Support)

  • dwSlaveId – [in] Slave ID

  • achFileName – [in] File name of slave file to write

  • dwFileNameLen – [in] Length of slave file name in bytes

  • pbyData – [in] Buffer containing transfered data

  • dwDataLen – [in] Buffer length [bytes]

  • dwPassword – [in] slave password

  • dwTimeout – [in] Timeout [ms] The function will block at most for this time.

Returns

See also

emGetSlaveId()

The following example demonstrates how to download files from the Master to the Slave using FoE.

6.12.3. emFoeFileUpload

static EC_T_DWORD ecatFoeFileUpload(EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_BYTE *pbyData, EC_T_DWORD dwDataLen, EC_T_DWORD *pdwOutDataLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)
EC_T_DWORD emFoeFileUpload(EC_T_DWORD dwInstanceID, EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_BYTE *pbyData, EC_T_DWORD dwDataLen, EC_T_DWORD *pdwOutDataLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)

Execute a FoE File upload from an EtherCAT slave device.

This function is used to upload a complete file. The function returns after the upload has been successfully completed or an error has occurred. This function may not be called from within the JobTask’s context.

Parameters
  • dwInstanceID – [in] Instance ID (Multiple EtherCAT Network Support)

  • dwSlaveId – [in] Slave ID

  • achFileName – [in] File name of slave file to read.

  • dwFileNameLen – [in] Length of slave file name in bytes.

  • pbyData – [out] Buffer receiving transfered data

  • dwDataLen – [in] Buffer length [bytes]

  • pdwOutDataLen – [out] Length of received data [byte]

  • dwPassword – [in] slave password

  • dwTimeout – [in] Timeout [ms] The function will block at most for this time.

Returns

See also

emGetSlaveId()

6.12.4. emFoeDownloadReq

static EC_T_DWORD ecatFoeDownloadReq(EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)
EC_T_DWORD emFoeDownloadReq(EC_T_DWORD dwInstanceID, EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)

Initiates an FoE File download to an EtherCAT slave device.

This function is used to download a complete file and returns immediately. After the download has been successfully completed or an error has occurred, EC_NOTIFY_MBOXRCV is raised. The progress of the file transfer is also notified with EC_NOTIFY_MBOXRCV.

Deprecated:

EC_NOWAIT as a timeout is still accepted for reasons of compatibility and sets the timeout to 10 seconds

Parameters
  • dwInstanceID – [in] Instance ID (Multiple EtherCAT Network Support)

  • pMbxTfer – [in] Mailbox transfer object

  • dwSlaveId – [in] Slave ID

  • achFileName – [in] File name of slave file to write.

  • dwFileNameLen – [in] Length of slave file name in bytes.

  • dwPassword – [in] slave password

  • dwTimeout – [in] Timeout [ms]

Returns

See also

emGetSlaveId()

6.12.5. emFoeSegmentedDownloadReq

static EC_T_DWORD ecatFoeSegmentedDownloadReq(EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *szFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwFileSize, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)
EC_T_DWORD emFoeSegmentedDownloadReq(EC_T_DWORD dwInstanceID, EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *szFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwFileSize, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)

Initiates or continues a segmented FoE File download to an EtherCAT slave device.

This function is used to download a file chunk-by-chunk and returns immediately. An EC_NOTIFY_MBOXRCV is raised to request the next chunk from the application or to provide information about the progress and the change in the transfer status.

The slave may have a different mailbox size for BOOTSTRAP than for PREOP, SAFEOP, OP. See

EC_T_CFG_SLAVE_INFO.dwMbxInSize2. The maximum chunk size is the slave’s mailbox size - 12 bytes overhead for EtherCAT’s FoE protocol. The mailbox transfer object’s buffer must be at least as big as the chunks to be transferred.

Deprecated:

EC_NOWAIT as a timeout is still accepted for reasons of compatibility and sets the timeout to 10 seconds

Parameters
  • dwInstanceID – [in] Instance ID (Multiple EtherCAT Network Support)

  • pMbxTfer – [in] Pointer to the corresponding mailbox transfer object. EC_T_MBXTFER.pbyMbxTferData: next chunk, EC_T_MBXTFER.dwDataLen: next chunk size.

  • dwSlaveId – [in] Slave ID

  • szFileName – [in] File name of slave file to write. Only evaluated when initiating the request.

  • dwFileNameLen – [in] Length of slave file name in bytes

  • dwFileSize – [in] Complete file size (mandatory). Used also for progress information. Only evaluated when initiating the request.

  • dwPassword – [in] Slave password. Only evaluated when initiating the request.

  • dwTimeout – [in] Timeout [ms] specify the overall timeout of the FoE transfer. Only evaluated when initiating the request.

Returns

6.12.6. emFoeUploadReq

static EC_T_DWORD ecatFoeUploadReq(EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)
EC_T_DWORD emFoeUploadReq(EC_T_DWORD dwInstanceID, EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *achFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)

Initiates an FoE File upload from an EtherCAT slave device.

This function is used to upload a complete file and returns immediately. After the upload has been successfully completed or an error has occurred, EC_NOTIFY_MBOXRCV is raised. The progress of the file transfer is also notified with EC_NOTIFY_MBOXRCV.

Deprecated:

EC_NOWAIT as a timeout is still accepted for reasons of compatibility and sets the timeout to 10 seconds

Parameters
  • dwInstanceID – [in] Instance ID (Multiple EtherCAT Network Support)

  • pMbxTfer – [in] Mailbox transfer object

  • dwSlaveId – [in] Slave ID

  • achFileName – [in] File name of slave file to read.

  • dwFileNameLen – [in] Length of slave file name in bytes.

  • dwPassword – [in] slave password

  • dwTimeout – [in] Timeout [ms]

Returns

See also

emGetSlaveId()

6.12.7. emFoeSegmentedUploadReq

static EC_T_DWORD ecatFoeSegmentedUploadReq(EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *szFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwFileSize, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)
EC_T_DWORD emFoeSegmentedUploadReq(EC_T_DWORD dwInstanceID, EC_T_MBXTFER *pMbxTfer, EC_T_DWORD dwSlaveId, const EC_T_CHAR *szFileName, EC_T_DWORD dwFileNameLen, EC_T_DWORD dwFileSize, EC_T_DWORD dwPassword, EC_T_DWORD dwTimeout)

Initiates or continues a segmented FoE File upload from an EtherCAT slave device.

This function is used to upload a file chunk-by-chunk and returns immediately. An EC_NOTIFY_MBOXRCV is raised to provide the next chunk to the application or to get information about the progress and the change in the transfer status.

The slave may have a different mailbox size for BOOTSTRAP than for PREOP, SAFEOP, OP. See

EC_T_CFG_SLAVE_INFO.dwMbxInSize2. The maximum chunk size is the slave’s mailbox size - 12 bytes overhead for EtherCAT’s FoE protocol. The mailbox transfer object’s buffer must be at least as big as the chunks to be transferred.

Deprecated:

EC_NOWAIT as a timeout is still accepted for reasons of compatibility and sets the timeout to 10 seconds

Parameters
  • dwInstanceID – [in] Instance ID (Multiple EtherCAT Network Support)

  • pMbxTfer – [in] Pointer to the corresponding mailbox transfer object. EC_T_MBXTFER.pbyMbxTferData: next chunk, EC_T_MBXTFER.dwDataLen: next chunk size.

  • dwSlaveId – [in] Slave ID

  • szFileName – [in] File name of slave file to write. Only evaluated when initiating the request.

  • dwFileNameLen – [in] Length of slave file name in bytes.

  • dwFileSize – [in] Used only for progress information.

  • dwPassword – [in] Slave password. Only evaluated when initiating the request.

  • dwTimeout – [in] Timeout [ms] specify the overall timeout of the FoE transfer. Only evaluated when initiating the request.

Returns

The following example demonstrates how to upload a file in segments:

6.12.8. emConvertEcErrorToFoeError

EC_T_DWORD ecatConvertEcErrorToFoeError(EC_T_DWORD dwErrorCode)
EC_T_DWORD emConvertEcErrorToFoeError(EC_T_DWORD dwInstanceID, EC_T_DWORD dwErrorCode)

Convert master error code to FoE error code.

Returns

FoE error code according to ETG1000.6 Table 92 - Error codes of FoE

6.12.9. emNotify - EC_NOTIFY_FOE_MBXSND_WKC_ERROR

This error will be indicated in case the working counter of a FoE mailbox write command was not set to the expected value of 1. Detailed error information is stored in structure EC_T_WKCERR_DESC of the union element WkcErrDesc.

struct EC_T_WKCERR_DESC
EC_T_SLAVE_PROP SlaveProp
EC_T_BYTE byCmd
EC_T_DWORD dwAddr
EC_T_WORD wWkcSet
EC_T_WORD wWkcAct

6.12.10. emNotify - EC_NOTIFY_FOE_MBSLAVE_ERROR

This error will be indicated in case a FoE mailbox slave send an error message. Detailed error information is stored in structure EC_T_MBOX_FOE_ABORT_DESC of the union element FoeErrorDesc.

struct EC_T_MBOX_FOE_ABORT_DESC

Public Members

EC_T_SLAVE_PROP SlaveProp

Slave properties

EC_T_DWORD dwErrorCode

Error code

EC_T_CHAR achErrorString[MAX_STD_STRLEN]

FoE error string

6.12.11. Extending EC_T_MBX_DATA

FoE transfer data, e.g. progress information in notification.

struct EC_T_MBX_DATA_FOE

Public Members

EC_T_DWORD dwTransferredBytes

[out] amount of transferred bytes

EC_T_DWORD dwRequestedBytes

[out] amount of bytes to be provided by application

EC_T_DWORD dwBusyDone

[out] If slave is busy: 0 … dwBusyEntire

EC_T_DWORD dwBusyEntire

[out] If dwBusyEntire > 0: Slave is busy

EC_T_CHAR szBusyComment[EC_FOE_BUSY_COMMENT_SIZE]

[out] Busy Comment from slave

EC_T_DWORD dwFileSize

[out] File size

EC_T_WORD wStationAddress

[out] Station address of the slave