Author Topic: File operations  (Read 4103 times)

Ken Akridge

  • Jr. Member
  • **
  • Posts: 2
    • View Profile
File operations
« on: August 28, 2016, 01:41:50 PM »
I have been able to create a  file in EEProm  using      int16_t f = CleO.FOpen("@test.txt", FILE_CREATE_ALWAYS | FILE_WRITE);

I have been able to read that file in EEProm  using      int16_t g = CleO.FOpen("@test.txt", FILE_READ);

How can I perform the same operations on the SD card ?

There seems to be no centralized place to learn the operations in the API.

                                 -ken

Fred Dart

  • CEO of FTDI
  • Administrator
  • Full Member
  • *****
  • Posts: 74
  • Welcome...
    • View Profile
    • FTDI CleO Page
Re: File operations
« Reply #1 on: August 29, 2016, 06:37:56 AM »
Remove the @ at the start of the file name to access the SD card. File names starting with @ mean the e-Flash. E.g. @test.txt means file test.txt on the eFlash drive. The @ is stripped off. We'll try and make this clearer in the documentation.

Ken Akridge

  • Jr. Member
  • **
  • Posts: 2
    • View Profile
Re: File operations
« Reply #2 on: August 31, 2016, 01:38:27 AM »
So can you give me an example of how I would go about:

     1.  creating a file on the SD card named "ken.txt"
     2.  writing "This is a test." to the file
     3.  closing the file
     4.  opening "ken.txt" and printing out the text contained therein
     5.  closing the file

                                        thank you,
                                             -ken


CleOSupport

  • Administrator
  • Full Member
  • *****
  • Posts: 51
    • View Profile
Re: File operations
« Reply #3 on: August 31, 2016, 01:35:56 PM »
Hello Ken,

Here is a small example which does this.

Best Regards, CleOSupport

Code: [Select]
/* (C) Copyright Future Technology Devices International Ltd.
 * ============================================================================
 *
 * This source code ("the Software") is provided by Future Technology Devices
 * International Limited ("FTDI") subject to the licence terms set out
 * http://www.ftdichip.com/FTSourceCodeLicenceTerms.htm ("the Licence Terms").
 * You must read the Licence Terms before downloading or using the Software.
 * By installing or using the Software you agree to the Licence Terms. If you
 * do not agree to the Licence Terms then do not download or use the Software.
 */
#include <SPI.h>
#include <CleO.h>


void setup()
{
  char STR1[] = "This is a test";
  char buf[30];
  uint8_t ReadBuffer[30];
  int16_t actual;
  uint32_t u32;

  /* ################################################################################## */
  /* INITIALISE CleO  AND BEGIN NEW SCREEN */
  /* ################################################################################## */

  /* Initialize CleO - needs to be done only once */
  CleO.begin();

  /* Start building a screen frame */
  CleO.Start();

  /* ################################################################################## */
  /* WRITING THE DATA TO THE FILE */
  /* ################################################################################## */

  /* open file for write */
  CleO.StringExt(FONT_SANS_2, 160, 20, LIGHT_GREEN, TM, 0, 0, "Creating Ken.txt...");
  int16_t f = CleO.FOpen("Ken.txt", FILE_CREATE_ALWAYS | FILE_WRITE);

  /* Display message to user*/
  sprintf(buf, "Writing: %s", STR1);  // Create message to be displayed on CleO screen
  CleO.StringExt(FONT_SANS_2, 160, 60, LIGHT_GREEN, TM, 0, 0, buf);

  /* write into file */
  CleO.FWrite(f, strlen(STR1) + 1, (uint8_t*)STR1, actual);

  /* print number of bytes written */
  sprintf(buf, "%d bytes written", actual);
  CleO.StringExt(FONT_SANS_2, 160, 100, LIGHT_GREEN, TM, 0, 0, buf);

  /* close file using file handle */
  CleO.FClose(f);
  /* ################################################################################## */
  /* READING THE DATA BACK FROM THE FILE */
  /* ################################################################################## */

  /* Open test.txt file in read mode */
  CleO.StringExt(FONT_SANS_2, 160, 140, LIGHT_GREEN, TM, 0, 0, "Opening Ken.txt...");
  f = CleO.FOpen("Ken.txt", FILE_READ);

  /* request for file size */
  CleO.FSize(f, u32);
  sprintf(buf, "File size:%d bytes", u32);
  CleO.StringExt(FONT_SANS_2, 160, 180, LIGHT_GREEN, TM, 0, 0, buf);

  /* read the text from the file */
  CleO.FGetS(f, ReadBuffer, u32);
  sprintf(buf, "Text read: %s", ReadBuffer);
  CleO.StringExt(FONT_SANS_2, 160, 220, LIGHT_GREEN, TM, 0, 0, (char *) buf);

  /* close file using file handle */
  CleO.FClose(f);

  /* ################################################################################## */
  /* DISPLAY COMPLETED FRAME */
  /* ################################################################################## */
 
  /* Display completed screen frame */
  CleO.Show();

}


void loop()
{
  // Wait here once finished
}

« Last Edit: August 31, 2016, 01:42:55 PM by CleOSupport »

KySawdust

  • Full Member
  • ***
  • Posts: 9
    • View Profile
Re: File operations
« Reply #4 on: August 31, 2016, 08:18:43 PM »
Since I don't have the SD card yet, how do I change the code above to write to the internal storage?  And can I create directories on the internal storage?
KySawdust

prashanthb

  • Full Member
  • ***
  • Posts: 23
    • View Profile
Re: File operations
« Reply #5 on: September 01, 2016, 04:58:24 AM »
Hi Ken,

Folder related CleO commands are under development and hence are not exposed in CleO commands. Support for folder related commands will be added in next release, for time being kindly use PC to create the folders in SDCard and perform file-based operations via CleO commands.

KySawdust

  • Full Member
  • ***
  • Posts: 9
    • View Profile
Re: File operations
« Reply #6 on: September 01, 2016, 08:40:19 AM »
Sorry, you missed the first question.

Since I don't have the SD card yet, how do I change the code above to write to the internal storage? 

Thank you sir!
KySawdust

CleOSupport

  • Administrator
  • Full Member
  • *****
  • Posts: 51
    • View Profile
Re: File operations
« Reply #7 on: September 01, 2016, 09:03:02 AM »
Hello,

For file operations with the internal memory, please put an @ sign in the name. A path with @ will point to eFlash and a path without @ will point to the SD card.

e.g.   int16_t im = CleO.LoadImageFile("@Pictures/ctg.jpg", 0);

Best Regards, CleOSupport

pnaeeni

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: File operations
« Reply #8 on: September 11, 2016, 09:37:01 AM »
hi. can i play an AVI file from SD on LCD and then display some PNG file transparent on it (top layer)?the png files and avi files are on sd card. can you help me for this?
i want to program cloe with f903 . i dont want use arduino. is it possible?

CleOSupport

  • Administrator
  • Full Member
  • *****
  • Posts: 51
    • View Profile
Re: File operations
« Reply #9 on: September 13, 2016, 05:04:00 PM »
Hello,

CleO is designed for interfacing to Arduino rather than for programming your application to the on-board FT903 MCU.

The FTDI eval boards for the FT810 and FT900 (ME810A-HV35R and MM900EV1A/lite) can be used together if you wish to write your code for the FT900 MCU itself.

Best Regards, CleOSupport