এসডি কার্ড#
ভূমিকা#
sdcard ক্লাসটি brain বেস ক্লাস থেকে উদ্ভূত এবং EXP Brain-এ ঢোকানো একটি অপসারণযোগ্য SD কার্ডে সংরক্ষিত ফাইলগুলিতে অ্যাক্সেস প্রদান করে।
এসডি কার্ড ব্যবহার করে আপনার রোবট ছবির মতো ডেটা লোড করতে, ফাইল পড়তে ও লিখতে এবং পরবর্তী ব্যবহারের জন্য বা কম্পিউটারে স্থানান্তরের জন্য তথ্য সংরক্ষণ করতে পারে।
Access#
Brain.SDcard
Notes#
EXP Brain ৩২ জিবি পর্যন্ত আকারের এসডি কার্ড সমর্থন করে।
এসডি কার্ডটি অবশ্যই FAT32 ফরম্যাটে ফরম্যাট করতে হবে।
৩২ জিবির চেয়ে বড় এসডি কার্ডগুলো সাধারণত exFAT ফরম্যাটে ফরম্যাট করা হয়, যা EXP Brain-এর সাথে সামঞ্জস্যপূর্ণ নয়।
অ্যাক্সেসযোগ্য হওয়ার জন্য সমস্ত ফাইল অবশ্যই এসডি কার্ডের রুট ডিরেক্টরিতে রাখতে হবে।
ফাইল সংক্রান্ত কাজ করার আগে এসডি কার্ডটি ব্রেইন-এ ঢোকাতে হবে।
ফাইলের নাম এবং পাথ কেস-সেনসিটিভ।
Example#
/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */
// Create the EXP 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— ব্যবহারকারীর দেওয়া বাফার থেকে ডেটা EXP ব্রেইনের SD কার্ডের একটি ফাইলে সংরক্ষণ করে।appendfile— EXP Brain-এর SD কার্ডে থাকা কোনো ফাইলের শেষে ব্যবহারকারীর দেওয়া বাফার থেকে ডেটা যুক্ত করে।isInserted— ব্রেইনে একটি SD কার্ড ঢোকানো আছে কিনা তা ফেরত দেয়।size— EXP Brain-এর SD কার্ডে সংরক্ষিত একটি ফাইলের আকার ফেরত দেয়।exists— EXP Brain-এর SD কার্ডে নির্দিষ্ট নামের ফাইলটি আছে কিনা তা ফেরত দেয়।
এসডি কার্ডে সংরক্ষিত .bmp এবং .png ফাইলগুলি drawImageFromFile ব্যবহার করে EXP ব্রেইন স্ক্রিনে প্রদর্শন করা যেতে পারে, যা Brain.Screen এর মাধ্যমে অ্যাক্সেস করা হয়।
যেকোনো sdcard মেম্বার ফাংশন কল করার আগে, brain একটি ইনস্ট্যান্স তৈরি করতে হবে, যা নিচে দেখানো হয়েছে:
// Create the Brain
brain Brain = brain();
loadfile#
এসডি কার্ড থেকে কোনো ফাইলের বিষয়বস্তু ব্যবহারকারীর দেওয়া মেমোরি বাফারে লোড করে।
Available Functionsint32_t loadfile(
const char* name,
uint8_t* buffer,
int32_t len );
প্যারামিটার |
প্রকার |
বর্ণনা |
|---|---|---|
|
|
এসডি কার্ড থেকে লোড করার ফাইলের নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে। |
|
|
একটি বাফারের পয়েন্টার যেখানে ফাইলের ডেটা সংরক্ষণ করা হবে। |
|
|
ফাইল থেকে পড়ার জন্য সর্বাধিক বাইট সংখ্যা, যা সাধারণত বাফারের আকারের সমান করে সেট করা হয়। |
ফাইল থেকে সফলভাবে পঠিত বাইটের সংখ্যা নির্দেশ করে একটি int32_t রিটার্ন করে:
একটি ধনাত্মক মান নির্দেশ করে যে বাফারে কত বাইট লোড করা হয়েছে।
0নির্দেশ করে যে কোনো ডেটা পড়া হয়নি।
ফাইলটির আকার
lenবাইট থেকে বড় হলে, শুধুমাত্র প্রথমlenবাইট পড়া হয়।অনুরোধ করা ডেটা ধারণ করার জন্য বাফারটি যথেষ্ট বড় হতে হবে।
এই ফাংশনটি সরাসরি বাইট পড়ে এবং এর শেষে কোনো নাল টার্মিনেটর যুক্ত করে না।
// 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#
ব্যবহারকারীর দেওয়া বাফার থেকে ডেটা EXP Brain-এর SD কার্ডের একটি ফাইলে সংরক্ষণ করে।
Available Functionsint32_t savefile(
const char* name,
uint8_t* buffer,
int32_t len );
প্যারামিটার |
প্রকার |
বর্ণনা |
|---|---|---|
|
|
ফাইলটির নাম স্ট্রিং হিসেবে সংরক্ষণ করতে হবে। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে। |
|
|
ফাইলে লেখার জন্য ডেটা ধারণকারী একটি মেমরি বাফারের পয়েন্টার। |
|
|
বাফার থেকে ফাইলে লেখার জন্য বাইটের সংখ্যা। |
ফাইলে সফলভাবে লেখা বাইটের সংখ্যা নির্দেশ করে একটি int32_t রিটার্ন করে:
একটি ধনাত্মক মান নির্দেশ করে কত বাইট সংরক্ষণ করা হয়েছে।
0নির্দেশ করে যে কোনো ডেটা লেখা হয়নি।
ফাইলটির আকার
lenবাইট থেকে বড় হলে, শুধুমাত্র প্রথমlenবাইট পড়া হয়।যদি একই নামের কোনো ফাইল আগে থেকেই বিদ্যমান থাকে, তবে সেটি মুছে ফেলা হবে।
এই ফাংশনটি মেমরি বরাদ্দ করে না; বাফারটি ব্যবহারকারীকেই তৈরি ও পরিচালনা করতে হবে।
ফাংশনটি সরাসরি বাইট লেখে এবং শেষে কোনো নাল টার্মিনেটর যুক্ত করে না।
// 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#
EXP Brain-এর SD কার্ডে থাকা কোনো বিদ্যমান ফাইলের শেষে ব্যবহারকারী-প্রদত্ত বাফার থেকে ডেটা যুক্ত করে।
Available Functionsint32_t appendfile(
const char* name,
uint8_t* buffer,
int32_t len );
প্যারামিটার |
প্রকার |
বর্ণনা |
|---|---|---|
|
|
এসডি কার্ডে ডেটা যুক্ত করার জন্য ফাইলের নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে। |
|
|
ফাইলে যুক্ত করার জন্য ডেটা ধারণকারী একটি মেমরি বাফারের পয়েন্টার। |
|
|
বাফার থেকে ফাইলে যুক্ত করার জন্য বাইটের সংখ্যা। |
ফাইলে সফলভাবে যুক্ত হওয়া বাইটের সংখ্যা নির্দেশ করে একটি int32_t রিটার্ন করে:
একটি ধনাত্মক মান নির্দেশ করে কত বাইট যুক্ত করা হয়েছে।
0নির্দেশ করে যে কোনো ডেটা যুক্ত করা হয়নি।
ফাইলটির আকার
lenবাইট থেকে বড় হলে, শুধুমাত্র প্রথমlenবাইট পড়া হয়।ফাইলটি অবশ্যই এসডি কার্ডে আগে থেকেই থাকতে হবে; এই ফাংশনটি কোনো নতুন ফাইল তৈরি করে না।
এই ফাংশনটি মেমরি বরাদ্দ করে না; বাফারটি ব্যবহারকারীকেই তৈরি ও পরিচালনা করতে হবে।
ফাংশনটি সরাসরি বাইট যুক্ত করে এবং কোনো নাল টার্মিনেটর যুক্ত করে না।
// 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#
EXP Brain-এ বর্তমানে কোনো SD কার্ড ঢোকানো আছে কিনা তা জানায়।
Available Functionsbool isInserted();
এই ফাংশনটি কোনো প্যারামিটার গ্রহণ করে না।
Return Valuesএসডি কার্ড ঢোকানো হয়েছে কিনা তা নির্দেশ করে একটি বুলিয়ান মান ফেরত দেয়:
true— EXP ব্রেইন-এ একটি SD কার্ড ঢোকানো আছে।false— কোনো এসডি কার্ড ঢোকানো নেই।
এই ফাংশনটি শুধুমাত্র এসডি কার্ডের উপস্থিতি পরীক্ষা করে; এটি কার্ডটি ফরম্যাট করা বা পাঠযোগ্য কিনা তা যাচাই করে না।
// 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#
EXP Brain-এর SD কার্ডে সংরক্ষিত ফাইলের আকার ফেরত দেয়।
Available Functionsint32_t size(
const char* name );
প্যারামিটার |
প্রকার |
বর্ণনা |
|---|---|---|
|
|
এসডি কার্ডে থাকা ফাইলটির নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে। |
ফাইলের আকার বাইটে প্রকাশ করে এমন একটি int32_t রিটার্ন করে:
ধনাত্মক মানটি ফাইলের আকার বাইটে নির্দেশ করে।
0নির্দেশ করে যে ফাইলটি খালি অথবা ফাইলটি খুঁজে পাওয়া যায়নি।
loadfileকল করার আগে একটি বাফার বরাদ্দ করতে ফেরত আসা আকারটি ব্যবহার করা যেতে পারে।
// 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#
EXP Brain-এর SD কার্ডে নির্দিষ্ট নামের কোনো ফাইল আছে কিনা তা জানায়।
Available Functionsbool exists(
const char* name );
প্যারামিটার |
প্রকার |
বর্ণনা |
|---|---|---|
|
|
এসডি কার্ডে যে ফাইলটি পরীক্ষা করতে হবে তার নাম। ফাইলের নামে অবশ্যই ফাইল এক্সটেনশন থাকতে হবে। |
ফাইলটি বিদ্যমান কিনা তা নির্দেশ করে একটি বুলিয়ান মান প্রদান করে:
true— এসডি কার্ডে নির্দিষ্ট নামের একটি ফাইল বিদ্যমান আছে।false— নির্দিষ্ট নামের কোনো ফাইল বিদ্যমান নেই।
// 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);
}