[Ethercat Device]
Description
Read a file from the EtherCAT slave device using FoE.
Syntax
int readFoE(char *filename, uint32_t password, void *data, uint32_t size, uint32_t timeout_ms = 2000);
Parameters
[in] char *filename
Name of the file to be read.[in] uint32_t password
32-bit password value. If the password is equal to zero, it indicates that the password is unused.[in] void *data
The file data buffer to be read.[in] uint32_t size
The size of the file data buffer to be read.[in] uint32_t timeout_ms
Timeout in milliseconds.
Return Value
Return the size of the file to be read. If the return value is less than 0, it indicates an error code.
Comment
The function must be called after EthercatMaster::begin()
. This function is blocking and cannot be called within the Cyclic Callback.
Example
#include "Ethercat.h" #define MAX_FILE_DATA_SIZE (2 * 1024 * 1024) EthercatMaster master; EthercatDevice_Generic slave; char destination[] = {"destination.bin"}; char filename[] = {"firmware.bin"}; uint32_t password = 0; uint8_t *filedata; int filesize; FILE *file; void setup() { master.begin(); slave.attach(0, master); filedata = (uint8_t *)malloc(MAX_FILE_DATA_SIZE); if (filedata != NULL) { filesize = slave.readFoE(filename, password, filedata, MAX_FILE_DATA_SIZE); file = fopen(destination, "wb"); if (file != NULL) { fwrite(filedata, sizeof(uint8_t), filesize, file); fclose(file); } free(filedata); } } void loop() { // put your main code here, to run repeatedly: }
Please see the EtherCAT Library User Manual for more QEC EtherCAT instructions and API usage.