Description

The i_FileTrans_SendFile() – function transfers a file from SerialFlash over a serial connection, typically a CAN2SER link to the PC or another dice device. The i_FileTrans_SendFile() function let the sender wait for the receiver to trigger the process by an enquiry-signal. This happens when the receiver calls the i_FileTrans_ReceiveFile() function.

Syntax

i_FileTrans_SendFile( oac_Filename, op_Serial, op_SerFlash );

Parameters

char* oac_Filename: pointer to a zero terminated char-array of the filename; max. 32 bytes
HardwareSerial* op_Serial: pointer to the serial interface or derived class like CAN2SER (e.g. &Serial)
SerialFlashChip* op_SerFlash: pointer to the SerialFlash object (typ. &SerialFlash)

Returns

int: 1 – success

  • 0 – file does not exist
  • -1 – file could not be opened
  • -2 – timeout – no ‘enquiry’ signal from receiver
  • -3 – error while sending file header
  • -4 – receiver rejected the file
  • -5 – error during data transmission
  • – no final confirmation from receiver

Example Code

#include "FileTransfer.h"
#include "SerialFlash.h"
void setup()
{
  SerialFlash.begin();
  while(!Serial);
}
void loop()
{	
  if(i_FileTrans_SendFile("dice-ascii-logo.txt", &Serial, &SerialFlash)== 1)
  {
     delay(1000);
     Serial.println("File transfered OK");
  }
}

Notes and Warnings

Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> FileTransfer

See also

Find more details here:

CAN2SER – Library
SerialFlash – Library
SAMC21_CAN – Library
Device addressing