I want to find...

Search

Shares

Table of Content

EthercatDevice.writeFoE()

[Ethercat Device]

Description

Write a file to the EtherCAT slave device using FoE.

Syntax

int writeFoE(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 written.
  • [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 written.
  • [in] uint32_t size
    The size of the file data buffer to be written.
  • [in] uint32_t timeout_ms
    Timeout in milliseconds.

Return Value

Return an error code. If the returned value is zero, it indicates a successful execution of this function.

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"

EthercatMaster master;
EthercatDevice_Generic slave;

char source[] = {"source.bin"};
char filename[] = {"firmware.bin"};
uint32_t password = 0;
uint8_t *filedata;
int filesize;
FILE *file;

void setup() {
  master.begin();
  slave.attach(0, master);

  file = fopen(source, "rb");
  if (file != NULL) {
    fseek(file, 0, SEEK_END);
    filesize = ftell(file);
    fseek(file, 0, SEEK_SET);
    filedata = (uint8_t *)malloc(filesize);
    if (filedata != NULL) {
      fread(filedata, sizeof(uint8_t), filesize, file);
      slave.writeFoE(filename, password, filedata, filesize);
      free(filedata);
    }
    fclose(file);
  }
}

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.

Leave a Comment

Scroll to Top