サイト内検索

検索

Shares

Table of Content

EthercatDevice.readFoE()

[Ethercat Device]

説明

FoEを使うEtherCATスレーブデバイスからファイルを読み出します。

構文

int readFoE(char *filename, uint32_t password, void *data, uint32_t size, uint32_t timeout_ms = 2000);

媒介変数

  • [in] char *filename
    読み出すファイルの数。
  • [in] uint32_t password
    32ビット・パスワード値。パスワード値がゼロの場合、パスワードが使用されていないことを示します。
  • [in] void *data
    読み出すためのファイル・データ・バッファ。
  • [in] uint32_t size
    読み出すためのファイル・データ・バッファのサイズ。
  • [in] uint32_t timeout_ms
    タイムアウト値で、ミリ秒単位。

戻り値

読み出すファイルのサイズが返されます。返された値が 0未満の場合、 error codeを示します。.

備考

この関数は、 EthercatMaster::begin()が正常に実行された後で呼び出す必要があります。この関数はブロッキングされているため、循環コールバック関数内で呼び出すことができません。

#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:

}

詳細は EtherCAT Library User Manual QEC EtherCAT命令とAPI使用法参照

上部へスクロール