خانه » دانشنامه‌ها » دانشنامه آردوینو » اسامی افزایشی فایل ها در SD کارت
  1. خانه
  2. »
  3. دانشنامه‌ها
  4. »
  5. دانشنامه آردوینو
  6. »
  7. اسامی افزایشی فایل ها در SD کارت

اسامی افزایشی فایل ها در SD کارت

بازدید: 340

اسم فایل برای ثبت داده روی SD کارت

اسم فایل برای ثبت داده روی یک SD کارت می‌تواند با استفاده از دستورات تغییر کند تا یک فایل جدید به وجود بیاید و از پاک کردن فایل‌های موجود جلوگیری به عمل آید

اطلاعات از ماژول ساعت و سنسورها دریافت می‌شود و سپس روی SD کارت ثبت می‌شود. اسامی فایل‌ها به صورت اتوماتیک افزایش می‌یابد و اطلاعات جدید روی فایل‌های قبلی نوشته نمی‌شود. محتویات یک فایل و اطلاعات در مورد ساختار فایل‌ها روی SD کارت نمایش داده می شود.

اسم فایل برای ثبت داده روی یک SD کارت می‌تواند با استفاده از دستورات تغییر کند تا یک فایل جدید به وجود بیاید و از پاک کردن فایل‌های موجود جلوگیری به عمل آید به عنوان مثال فایل data4.csv تنها در صورتی ساخته می‌شود که فایل data3.csv موجود باشد. لیست دستورات زیر چگونگی انتخاب اسامی افزایشی برای فایل‌ها و ثبت آن‌ها روی SD کارت را نشان می‌دهد. در اینجا نام فایل اولیه data.csv می‌باشد و سپس فایل‌های data1.csv، data2.csv و … ساخته می شوند.

filename=basefile+string(file count) + “.csv”

				
					#include <SPI.h>            // include SPI library
#include <SD.h>             // include SD library
File file;                  // #associate file with SD library
int CSpin = 10;             // #chip select pin for SD card
String filename;
String basefile = "data";   // #default filename is data.csv
bool filefound = false;
int filecount = 0;          // #for incrementing filename
int count = 0;
String data;                // data to write to SD card
void setup()
{
  Serial.begin(9600);       // #define Serial output baud rate
  if(SD.begin(CSpin) == 0)
  {
    Serial.println("Card fail");  // #return to void loop() if SD card not found
    return;
  }
  Serial.println("Card OK");
  filename=basefile + ".csv";   // generate filename
  while (filefound == 0)        // #search for file with filename
  {
    if(SD.exists(filename)>0)   // #if filename exists on SD card,
    {                           // #then increment filename counter
      filecount++;              // generate new filename
      filename = basefile + String(filecount) + ".csv";
    }
    else filefound = true; // #flag file with filename located on SD card
  }
  file = SD.open(filename, FILE_WRITE);   // #open file on SD card
  if(file == 1)
  {
    Serial.print(filename);Serial.println(" created");
    data = "Count";             // column header
   file.println(data);         // #write column header to file
    file.close();               // #close file after writing to SD card
  }
  else Serial.println("Couldn't access file"); // file not opened
}
void loop()
{
  count = count + 1;            // #incremental counter
  data = String(count);         // #convert counter to string
  File file = SD.open(filename, FILE_WRITE); // #open file on SD card
  if(file == 1) file.println(data);   // #write data string to file on SD card
  file.close();                       // #close file on SD card
  delay(1000);                        // #delay 1s before next count
}

				
			

لیست کردن فایل‌ها روی یک SD کارت‌

جزئیات یک فایل ( اسم ، اندازه بر حسب بایت) می‌تواند با استفاده از کد بالا نشان داده شود. تابع ()list چک می‌کند که یک فایل دایرکتوری است و اسم دایرکتوری را نمایش می‌دهد. اگر فایل دایرکتوری نباشد، جزئیات فایل‌های داخل دایرکتوری نمایش داده می شود.

کد نشان دادن محتویات روی sd کارت :

				
					#include <SPI.h>           // #include SPI library
#include <SD.h>            // #include SD library
File file;                 // #associate file with SD library
int CSpin = 10;            // #chip select pin
void setup()
{
  Serial.begin(9600);      // #define Serial output baud rate
  if(SD.begin(CSpin) == 0) // #check for presence of SD card
  {
    Serial.println("Card fail");  // #return to void setup() if SD card not found
    return;
  }
  Serial.println("Card OK");
  file = SD.open("/");       // #open SD directory of file information
  list(file, 0);             // #function to display file information
}
void loop()                  // #nothing in void loop() function
{}
void list(File direct, int nfiles) // #function to display file information
{
  while (1)                      // #list function only runs once
  {
    File entry =  direct.openNextFile(); // #next file in directory
    if (entry == 0) break;               // #stop at end of directory
    if (entry.isDirectory())             // #check is file is a directory
    {
      Serial.print(entry.name());        // #display directory name
      Serial.println("\tis a directory");
      list(entry, nfiles+1);     // #only list details of files
    }
    else
    {
      Serial.print(entry.name());Serial.print("\t"); # // display file name
      Serial.println(entry.size());      // #display file size (bytes)
    }
    entry.close();
  }
}

				
			

نظرتان را درباره این مقاله بگویید 4 نظر

اسامی افزایشی فایل ها در SD کارت

با ثبت نظر و نوشتن کامنت، تیم ما را در راستای بهبود و افزایش کیفیت محتوا یاری خواهید کرد :)

فهرست مطالب

مقالات مرتبط

بروزترین مقالات

این مقاله را با دوستانتان به اشتراک بگذارید!

اسم فایل برای ثبت داده روی SD کارت

اسامی افزایشی فایل ها در SD کارت

فهرست مطالب

اسم فایل برای ثبت داده روی یک SD کارت می‌تواند با استفاده از دستورات تغییر کند تا یک فایل جدید به وجود بیاید و از پاک کردن فایل‌های موجود جلوگیری به عمل آید

اطلاعات از ماژول ساعت و سنسورها دریافت می‌شود و سپس روی SD کارت ثبت می‌شود. اسامی فایل‌ها به صورت اتوماتیک افزایش می‌یابد و اطلاعات جدید روی فایل‌های قبلی نوشته نمی‌شود. محتویات یک فایل و اطلاعات در مورد ساختار فایل‌ها روی SD کارت نمایش داده می شود.

اسم فایل برای ثبت داده روی یک SD کارت می‌تواند با استفاده از دستورات تغییر کند تا یک فایل جدید به وجود بیاید و از پاک کردن فایل‌های موجود جلوگیری به عمل آید به عنوان مثال فایل data4.csv تنها در صورتی ساخته می‌شود که فایل data3.csv موجود باشد. لیست دستورات زیر چگونگی انتخاب اسامی افزایشی برای فایل‌ها و ثبت آن‌ها روی SD کارت را نشان می‌دهد. در اینجا نام فایل اولیه data.csv می‌باشد و سپس فایل‌های data1.csv، data2.csv و … ساخته می شوند.

filename=basefile+string(file count) + “.csv”

				
					#include <SPI.h>            // include SPI library
#include <SD.h>             // include SD library
File file;                  // #associate file with SD library
int CSpin = 10;             // #chip select pin for SD card
String filename;
String basefile = "data";   // #default filename is data.csv
bool filefound = false;
int filecount = 0;          // #for incrementing filename
int count = 0;
String data;                // data to write to SD card
void setup()
{
  Serial.begin(9600);       // #define Serial output baud rate
  if(SD.begin(CSpin) == 0)
  {
    Serial.println("Card fail");  // #return to void loop() if SD card not found
    return;
  }
  Serial.println("Card OK");
  filename=basefile + ".csv";   // generate filename
  while (filefound == 0)        // #search for file with filename
  {
    if(SD.exists(filename)>0)   // #if filename exists on SD card,
    {                           // #then increment filename counter
      filecount++;              // generate new filename
      filename = basefile + String(filecount) + ".csv";
    }
    else filefound = true; // #flag file with filename located on SD card
  }
  file = SD.open(filename, FILE_WRITE);   // #open file on SD card
  if(file == 1)
  {
    Serial.print(filename);Serial.println(" created");
    data = "Count";             // column header
   file.println(data);         // #write column header to file
    file.close();               // #close file after writing to SD card
  }
  else Serial.println("Couldn't access file"); // file not opened
}
void loop()
{
  count = count + 1;            // #incremental counter
  data = String(count);         // #convert counter to string
  File file = SD.open(filename, FILE_WRITE); // #open file on SD card
  if(file == 1) file.println(data);   // #write data string to file on SD card
  file.close();                       // #close file on SD card
  delay(1000);                        // #delay 1s before next count
}

				
			

لیست کردن فایل‌ها روی یک SD کارت‌

جزئیات یک فایل ( اسم ، اندازه بر حسب بایت) می‌تواند با استفاده از کد بالا نشان داده شود. تابع ()list چک می‌کند که یک فایل دایرکتوری است و اسم دایرکتوری را نمایش می‌دهد. اگر فایل دایرکتوری نباشد، جزئیات فایل‌های داخل دایرکتوری نمایش داده می شود.

کد نشان دادن محتویات روی sd کارت :

				
					#include <SPI.h>           // #include SPI library
#include <SD.h>            // #include SD library
File file;                 // #associate file with SD library
int CSpin = 10;            // #chip select pin
void setup()
{
  Serial.begin(9600);      // #define Serial output baud rate
  if(SD.begin(CSpin) == 0) // #check for presence of SD card
  {
    Serial.println("Card fail");  // #return to void setup() if SD card not found
    return;
  }
  Serial.println("Card OK");
  file = SD.open("/");       // #open SD directory of file information
  list(file, 0);             // #function to display file information
}
void loop()                  // #nothing in void loop() function
{}
void list(File direct, int nfiles) // #function to display file information
{
  while (1)                      // #list function only runs once
  {
    File entry =  direct.openNextFile(); // #next file in directory
    if (entry == 0) break;               // #stop at end of directory
    if (entry.isDirectory())             // #check is file is a directory
    {
      Serial.print(entry.name());        // #display directory name
      Serial.println("\tis a directory");
      list(entry, nfiles+1);     // #only list details of files
    }
    else
    {
      Serial.print(entry.name());Serial.print("\t"); # // display file name
      Serial.println(entry.size());      // #display file size (bytes)
    }
    entry.close();
  }
}

				
			

نظرتان را درباره این مقاله بگویید 4 نظر

اسامی افزایشی فایل ها در SD کارت

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

فروشگاه