एसडी कार्ड#

परिचय#

sdcard वर्ग brain आधार वर्ग से लिया गया है और वी5 ब्रेन में डाले गए हटाने योग्य एसडी कार्ड पर संग्रहीत फ़ाइलों तक पहुंच प्रदान करता है।

एसडी कार्ड का उपयोग करके, आपका रोबोट छवियों जैसे डेटा को लोड कर सकता है, फाइलों को पढ़ और लिख सकता है, और बाद में उपयोग के लिए जानकारी संग्रहीत कर सकता है या इसे कंप्यूटर पर स्थानांतरित कर सकता है।

Access#

Brain.SDcard

Notes#

  • V5 ब्रेन 32GB तक के SD कार्ड को सपोर्ट करता है।

  • एसडी कार्ड को FAT32 फॉर्मेट में फॉर्मेट किया जाना चाहिए।

    • 32GB से बड़े SD कार्ड आमतौर पर exFAT फॉर्मेट में होते हैं, जो V5 ब्रेन के साथ संगत नहीं है।

  • सभी फाइलों को एक्सेस करने योग्य होने के लिए एसडी कार्ड के रूट डायरेक्टरी में रखा जाना चाहिए।

  • फाइल संबंधी कार्यों को करने से पहले एसडी कार्ड को ब्रेन में डालना आवश्यक है।

  • फ़ाइल के नाम और पथ केस-संवेदनशील होते हैं।

Example#

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

// Create the V5 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 — उपयोगकर्ता द्वारा प्रदान किए गए बफर से डेटा को V5 ब्रेन के एसडी कार्ड पर एक फ़ाइल में सहेजता है।

  • appendfile — V5 ब्रेन के एसडी कार्ड पर मौजूद फ़ाइल के अंत में उपयोगकर्ता द्वारा प्रदान किए गए बफ़र से डेटा जोड़ता है।

  • isInserted — यह बताता है कि ब्रेन में एसडी कार्ड डाला गया है या नहीं।

  • size — V5 ब्रेन के एसडी कार्ड पर संग्रहीत फ़ाइल का आकार लौटाता है।

  • exists — यह बताता है कि V5 ब्रेन के SD कार्ड पर निर्दिष्ट नाम वाली कोई फ़ाइल मौजूद है या नहीं।

एसडी कार्ड पर संग्रहीत .bmp और .png फ़ाइलों को drawImageFromFile का उपयोग करके V5 ब्रेन स्क्रीन पर प्रदर्शित किया जा सकता है, जिसे Brain.Screen के माध्यम से एक्सेस किया जाता है।

किसी sdcard फ़ंक्शन को कॉल करने से पहले, brain बनाना आवश्यक है, जैसा कि नीचे दिखाया गया है:

// Create the V5 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#

यह उपयोगकर्ता द्वारा प्रदान किए गए बफर से डेटा को V5 ब्रेन के एसडी कार्ड पर एक फ़ाइल में सहेजता है।

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#

यह फ़ंक्शन उपयोगकर्ता द्वारा प्रदान किए गए बफ़र से डेटा को V5 ब्रेन के SD कार्ड पर मौजूद फ़ाइल के अंत में जोड़ता है।

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#

यह बताता है कि V5 ब्रेन में वर्तमान में कोई SD कार्ड लगा हुआ है या नहीं।

Available Functions
bool isInserted();

Parameters

यह फ़ंक्शन कोई पैरामीटर स्वीकार नहीं करता है।

Return Values

यह एक बूलियन मान लौटाता है जो यह दर्शाता है कि एसडी कार्ड डाला गया है या नहीं:

  • true — वी5 ब्रेन में एक एसडी कार्ड डाला गया है।

  • 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#

यह फ़ंक्शन V5 ब्रेन के SD कार्ड पर संग्रहीत फ़ाइल का आकार बताता है।

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#

यह बताता है कि V5 ब्रेन के SD कार्ड पर निर्दिष्ट नाम वाली कोई फ़ाइल मौजूद है या नहीं।

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);
}