এসডি কার্ড#

ভূমিকা#

sdcard ক্লাসটি brain বেস ক্লাস থেকে উদ্ভূত এবং IQ (2nd gen) Brain-এ ঢোকানো একটি অপসারণযোগ্য SD কার্ডে সংরক্ষিত ফাইলগুলিতে অ্যাক্সেস প্রদান করে।

এসডি কার্ড ব্যবহার করে আপনার রোবট ছবির মতো ডেটা লোড করতে, ফাইল পড়তে ও লিখতে এবং পরবর্তী ব্যবহারের জন্য বা কম্পিউটারে স্থানান্তরের জন্য তথ্য সংরক্ষণ করতে পারে।

Access#

Brain.SDcard

Notes#

  • IQ (২য় প্রজন্ম) ব্রেইন ৩২ জিবি পর্যন্ত এসডি কার্ড সমর্থন করে।

  • এসডি কার্ডটি অবশ্যই FAT32 ফরম্যাটে ফরম্যাট করতে হবে।

    • ৩২ জিবির চেয়ে বড় এসডি কার্ডগুলো সাধারণত exFAT ফরম্যাটে ফরম্যাট করা হয়, যা IQ (২য় প্রজন্ম) ব্রেইন-এর সাথে সামঞ্জস্যপূর্ণ নয়।

  • অ্যাক্সেসযোগ্য হওয়ার জন্য সমস্ত ফাইল অবশ্যই এসডি কার্ডের রুট ডিরেক্টরিতে রাখতে হবে।

  • ফাইল সংক্রান্ত কাজ করার আগে এসডি কার্ডটি ব্রেইন-এ ঢোকাতে হবে।

  • ফাইলের নাম এবং পাথ কেস-সেনসিটিভ।

Example#

/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */

// Create the Brain
brain Brain = brain();

// Add more text and display file size
if (Brain.SDcard.exists("Text.txt")) {
  // Get the size of the file
  int fileSize = Brain.SDcard.size("Text.txt");

  // Make a buffer to hold the file data
  uint8_t buffer[fileSize];

  // Load the file from the SD card into the buffer
  Brain.SDcard.loadfile("Text.txt", buffer, sizeof(buffer));

  // Display the file contents on the screen
  Brain.Screen.print("%s", buffer);
}

সদস্যদের কার্যাবলী#

sdcard ক্লাসে নিম্নলিখিত সদস্য ফাংশনগুলো অন্তর্ভুক্ত রয়েছে:

  • loadfile — এসডি কার্ড থেকে একটি ফাইলের বিষয়বস্তু ব্যবহারকারীর সরবরাহ করা মেমরি বাফারে লোড করে।

  • savefile — ব্যবহারকারীর দেওয়া বাফার থেকে ডেটা IQ (2nd gen) Brain-এর SD কার্ডের একটি ফাইলে সংরক্ষণ করে।

  • appendfile — IQ (2nd gen) Brain-এর SD কার্ডে থাকা কোনো ফাইলের শেষে ব্যবহারকারীর দেওয়া বাফার থেকে ডেটা যুক্ত করে।

  • isInserted — ব্রেইনে একটি SD কার্ড ঢোকানো আছে কিনা তা ফেরত দেয়।

  • size — IQ (2nd gen) Brain-এর SD কার্ডে সংরক্ষিত একটি ফাইলের আকার ফেরত দেয়।

  • exists — IQ (2nd gen) Brain-এর SD কার্ডে নির্দিষ্ট নামের কোনো ফাইল আছে কিনা তা ফেরত দেয়।

এসডি কার্ডে সংরক্ষিত .bmp এবং .png ফাইলগুলি drawImageFromFile ব্যবহার করে IQ (2nd gen) ব্রেইন স্ক্রিনে প্রদর্শন করা যেতে পারে, যা Brain.Screen এর মাধ্যমে অ্যাক্সেস করা হয়।

যেকোনো sdcard মেম্বার ফাংশন কল করার আগে, brain একটি ইনস্ট্যান্স তৈরি করতে হবে, যা নিচে দেখানো হয়েছে:

// Create the Brain
brain Brain = brain();

loadfile#

এসডি কার্ড থেকে কোনো ফাইলের বিষয়বস্তু ব্যবহারকারীর দেওয়া মেমোরি বাফারে লোড করে।

Available Functions
int32_t loadfile(
  const char* name,
  uint8_t* buffer,
  int32_t len );

Parameters

প্যারামিটার

প্রকার

বর্ণনা

name

const char*

এসডি কার্ড থেকে লোড করার ফাইলের নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে।

buffer

uint8_t*

একটি বাফারের পয়েন্টার যেখানে ফাইলের ডেটা সংরক্ষণ করা হবে।

len

int32_t

ফাইল থেকে পড়ার জন্য সর্বাধিক বাইট সংখ্যা, যা সাধারণত বাফারের আকারের সমান করে সেট করা হয়।

Return Values

ফাইল থেকে সফলভাবে পঠিত বাইটের সংখ্যা নির্দেশ করে একটি int32_t রিটার্ন করে:

  • একটি ধনাত্মক মান নির্দেশ করে যে বাফারে কত বাইট লোড করা হয়েছে।

  • 0 নির্দেশ করে যে কোনো ডেটা পড়া হয়নি।

Notes
  • ফাইলটির আকার lenবাইট থেকে বড় হলে, শুধুমাত্র প্রথম len বাইট পড়া হয়।

  • অনুরোধ করা ডেটা ধারণ করার জন্য বাফারটি যথেষ্ট বড় হতে হবে।

  • এই ফাংশনটি সরাসরি বাইট পড়ে এবং এর শেষে কোনো নাল টার্মিনেটর যুক্ত করে না।

Examples
// Check for SD card and show a file's text
if (Brain.SDcard.isInserted()) {
  // Create a message to save to the SD card
  uint8_t message[] = "Hello from VEX!";

  // Save the message into "Text.txt"
  Brain.SDcard.savefile("Text.txt", message, sizeof(message));

  // Get the size of the file
  int fileSize = Brain.SDcard.size("Text.txt");

  // Make a buffer to hold the file data
  uint8_t buffer[fileSize];

  // Load the file from the SD card into the buffer
  Brain.SDcard.loadfile("Text.txt", buffer, sizeof(buffer));

  // Display the file contents on the screen
  Brain.Screen.print("%s", buffer);
} else {
  Brain.Screen.print("Insert SD card");
}

savefile#

ব্যবহারকারীর দেওয়া বাফার থেকে ডেটা নিয়ে IQ (২য় প্রজন্ম) ব্রেইন-এর এসডি কার্ডের একটি ফাইলে সংরক্ষণ করে।

Available Functions
int32_t savefile(
  const char* name,
  uint8_t* buffer,
  int32_t len );

Parameters

প্যারামিটার

প্রকার

বর্ণনা

name

const char*

ফাইলটির নাম স্ট্রিং হিসেবে সংরক্ষণ করতে হবে। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে।

buffer

uint8_t*

ফাইলে লেখার জন্য ডেটা ধারণকারী একটি মেমরি বাফারের পয়েন্টার।

len

int32_t

বাফার থেকে ফাইলে লেখার জন্য বাইটের সংখ্যা।

Return Values

ফাইলে সফলভাবে লেখা বাইটের সংখ্যা নির্দেশ করে একটি int32_t রিটার্ন করে:

  • একটি ধনাত্মক মান নির্দেশ করে কত বাইট সংরক্ষণ করা হয়েছে।

  • 0 নির্দেশ করে যে কোনো ডেটা লেখা হয়নি।

Notes
  • ফাইলটির আকার lenবাইট থেকে বড় হলে, শুধুমাত্র প্রথম len বাইট পড়া হয়।

  • যদি একই নামের কোনো ফাইল আগে থেকেই বিদ্যমান থাকে, তবে সেটি মুছে ফেলা হবে।

  • এই ফাংশনটি মেমরি বরাদ্দ করে না; বাফারটি ব্যবহারকারীকেই তৈরি ও পরিচালনা করতে হবে।

  • ফাংশনটি সরাসরি বাইট লেখে এবং শেষে কোনো নাল টার্মিনেটর যুক্ত করে না।

Examples
// Check for SD card and show a file's text
if (Brain.SDcard.isInserted()) {
  // Create a message to save to the SD card
  uint8_t message[] = "Hello from VEX!";

  // Save the message into "Text.txt"
  Brain.SDcard.savefile("Text.txt", message, sizeof(message));

  // Get the size of the file
  int fileSize = Brain.SDcard.size("Text.txt");

  // Make a buffer to hold the file data
  uint8_t buffer[fileSize];

  // Load the file from the SD card into the buffer
  Brain.SDcard.loadfile("Text.txt", buffer, sizeof(buffer));

  // Display the file contents on the screen
  Brain.Screen.print("%s", buffer);
} else {
  Brain.Screen.print("Insert SD card");
}

appendfile#

IQ (২য় প্রজন্ম) ব্রেইন-এর এসডি কার্ডে থাকা কোনো বিদ্যমান ফাইলের শেষে ব্যবহারকারী-প্রদত্ত বাফার থেকে ডেটা যুক্ত করে।

Available Functions
int32_t appendfile(
  const char* name,
  uint8_t* buffer,
  int32_t len );

Parameters

প্যারামিটার

প্রকার

বর্ণনা

name

const char*

এসডি কার্ডে ডেটা যুক্ত করার জন্য ফাইলের নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে।

buffer

uint8_t*

ফাইলে যুক্ত করার জন্য ডেটা ধারণকারী একটি মেমরি বাফারের পয়েন্টার।

len

int32_t

বাফার থেকে ফাইলে যুক্ত করার জন্য বাইটের সংখ্যা।

Return Values

ফাইলে সফলভাবে যুক্ত হওয়া বাইটের সংখ্যা নির্দেশ করে একটি int32_t রিটার্ন করে:

  • একটি ধনাত্মক মান নির্দেশ করে কত বাইট যুক্ত করা হয়েছে।

  • 0 নির্দেশ করে যে কোনো ডেটা যুক্ত করা হয়নি।

Notes
  • ফাইলটির আকার lenবাইট থেকে বড় হলে, শুধুমাত্র প্রথম len বাইট পড়া হয়।

  • ফাইলটি অবশ্যই এসডি কার্ডে আগে থেকেই থাকতে হবে; এই ফাংশনটি কোনো নতুন ফাইল তৈরি করে না।

  • এই ফাংশনটি মেমরি বরাদ্দ করে না; বাফারটি ব্যবহারকারীকেই তৈরি ও পরিচালনা করতে হবে।

  • ফাংশনটি সরাসরি বাইট যুক্ত করে এবং কোনো নাল টার্মিনেটর যুক্ত করে না।

Examples
// Create a message to save to a new file
uint8_t message[] = "Hello";

// Save only the characters, not the null terminator
Brain.SDcard.savefile("Message.txt", message, sizeof(message) - 1);

// Load the file
int fileSize = Brain.SDcard.size("Message.txt");
uint8_t buffer[fileSize + 1];
Brain.SDcard.loadfile("Message.txt", buffer, fileSize);

// Add null terminator so it can be printed safely
buffer[fileSize] = 0;
Brain.Screen.print("%s\n", buffer);

// Create more text to append to the same file
uint8_t moreText[] = " World!";

// Append only the characters, not the null terminator
Brain.SDcard.appendfile("Message.txt", moreText, sizeof(moreText) - 1);

// Load the updated file
fileSize = Brain.SDcard.size("Message.txt");
uint8_t buffer2[fileSize + 1];
Brain.SDcard.loadfile("Message.txt", buffer2, fileSize);

// Add null terminator
buffer2[fileSize] = 0;
Brain.Screen.newLine();
Brain.Screen.print("%s", buffer2);

isInserted#

IQ (২য় প্রজন্ম) ব্রেইন-এ বর্তমানে কোনো SD কার্ড সংযুক্ত আছে কিনা তা জানায়।

Available Functions
bool isInserted();

Parameters

এই ফাংশনটি কোনো প্যারামিটার গ্রহণ করে না।

Return Values

এসডি কার্ড ঢোকানো হয়েছে কিনা তা নির্দেশ করে একটি বুলিয়ান মান ফেরত দেয়:

  • true — IQ (২য় প্রজন্ম) ব্রেইন-এ একটি SD কার্ড ঢোকানো আছে।

  • false — কোনো এসডি কার্ড ঢোকানো নেই।

Notes
  • এই ফাংশনটি শুধুমাত্র এসডি কার্ডের উপস্থিতি পরীক্ষা করে; এটি কার্ডটি ফরম্যাট করা বা পাঠযোগ্য কিনা তা যাচাই করে না।

Examples
// Check for SD card and show a file's text
if (Brain.SDcard.isInserted()) {
  // Create a message to save to the SD card
  uint8_t message[] = "Hello from VEX!";

  // Save the message into "Text.txt"
  Brain.SDcard.savefile("Text.txt", message, sizeof(message));

  // Get the size of the file
  int fileSize = Brain.SDcard.size("Text.txt");

  // Make a buffer to hold the file data
  uint8_t buffer[fileSize];

  // Load the file from the SD card into the buffer
  Brain.SDcard.loadfile("Text.txt", buffer, sizeof(buffer));

  // Display the file contents on the screen
  Brain.Screen.print("%s", buffer);
} else {
  Brain.Screen.print("Insert SD card");
  }

size#

IQ (২য় প্রজন্ম) ব্রেইন-এর এসডি কার্ডে সংরক্ষিত ফাইলের আকার ফেরত দেয়।

Available Functions
int32_t size(
  const char* name );

Parameters

প্যারামিটার

প্রকার

বর্ণনা

name

const char*

এসডি কার্ডে থাকা ফাইলটির নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে।

Return Values

ফাইলের আকার বাইটে প্রকাশ করে এমন একটি int32_t রিটার্ন করে:

  • ধনাত্মক মানটি ফাইলের আকার বাইটে নির্দেশ করে।

  • 0 নির্দেশ করে যে ফাইলটি খালি অথবা ফাইলটি খুঁজে পাওয়া যায়নি।

Notes
  • loadfile কল করার আগে একটি বাফার বরাদ্দ করতে ফেরত আসা আকারটি ব্যবহার করা যেতে পারে।

Examples
// Check for SD card and show a file's text
if (Brain.SDcard.isInserted()) {
  // Create a message to save to the SD card
  uint8_t message[] = "Hello from VEX!";

  // Save the message into "Text.txt"
  Brain.SDcard.savefile("Text.txt", message, sizeof(message));

  // Get the size of the file
  int fileSize = Brain.SDcard.size("Text.txt");

  // Make a buffer to hold the file data
  uint8_t buffer[fileSize];

  // Load the file from the SD card into the buffer
  Brain.SDcard.loadfile("Text.txt", buffer, sizeof(buffer));

  // Display the file contents on the screen
  Brain.Screen.print("%s", buffer);
} else {
  Brain.Screen.print("Insert SD card");
}

exists#

IQ (২য় প্রজন্ম) ব্রেইন-এর এসডি কার্ডে নির্দিষ্ট নামের কোনো ফাইল আছে কি না, তা জানায়।

Available Functions
bool exists(
  const char* name );

Parameters

প্যারামিটার

প্রকার

বর্ণনা

name

const char*

এসডি কার্ডে যে ফাইলটি পরীক্ষা করতে হবে তার নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে।

Return Values

ফাইলটি বিদ্যমান কিনা তা নির্দেশ করে একটি বুলিয়ান মান প্রদান করে:

  • true — এসডি কার্ডে নির্দিষ্ট নামের একটি ফাইল বিদ্যমান আছে।

  • false — নির্দিষ্ট নামের কোনো ফাইল বিদ্যমান নেই।

Examples
// Add more text and display file size
if (Brain.SDcard.exists("Text.txt")) {
  // Get the size of the file
  int fileSize = Brain.SDcard.size("Text.txt");

  // Make a buffer to hold the file data
  uint8_t buffer[fileSize];

  // Load the file from the SD card into the buffer
  Brain.SDcard.loadfile("Text.txt", buffer, sizeof(buffer));

  // Display the file contents on the screen
  Brain.Screen.print("%s", buffer);
}