എസ്ഡി കാർഡ്#
ആമുഖം#
sdcard ക്ലാസ് brain ബേസ് ക്ലാസിൽ നിന്ന് ഉരുത്തിരിഞ്ഞതാണ്, കൂടാതെ IQ (2nd gen) ബ്രെയിനിൽ തിരുകിയ ഒരു നീക്കം ചെയ്യാവുന്ന SD കാർഡിൽ സംഭരിച്ചിരിക്കുന്ന ഫയലുകളിലേക്ക് ആക്സസ് നൽകുന്നു.
SD കാർഡ് ഉപയോഗിച്ച്, നിങ്ങളുടെ റോബോട്ടിന് ചിത്രങ്ങൾ പോലുള്ള ഡാറ്റ ലോഡ് ചെയ്യാനും ഫയലുകൾ വായിക്കാനും എഴുതാനും പിന്നീട് ഉപയോഗിക്കാനോ കമ്പ്യൂട്ടറിലേക്ക് മാറ്റാനോ വേണ്ടി വിവരങ്ങൾ സംഭരിക്കാനും കഴിയും.
Access#
Brain.SDcard
Notes#
ഐക്യു (രണ്ടാം തലമുറ) ബ്രെയിൻ 32GB വരെയുള്ള SD കാർഡുകളെ പിന്തുണയ്ക്കുന്നു.
SD കാർഡ് FAT32 ആയി ഫോർമാറ്റ് ചെയ്തിരിക്കണം.
32GB-യിൽ കൂടുതലുള്ള SD കാർഡുകൾ സാധാരണയായി exFAT ആയി ഫോർമാറ്റ് ചെയ്യപ്പെടുന്നു, ഇത് IQ (രണ്ടാം തലമുറ) തലച്ചോറുമായി പൊരുത്തപ്പെടുന്നില്ല.
ആക്സസ് ചെയ്യുന്നതിനായി എല്ലാ ഫയലുകളും SD കാർഡിന്റെ റൂട്ട് ഡയറക്ടറിയിൽ സ്ഥാപിക്കണം.
ഫയൽ പ്രവർത്തനങ്ങൾ നടത്തുന്നതിന് മുമ്പ് SD കാർഡ് തലച്ചോറിൽ ചേർക്കണം.
ഫയൽ നാമങ്ങളും പാതകളും കേസ് സെൻസിറ്റീവ് ആണ്.
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— SD കാർഡിൽ നിന്ന് ഒരു ഫയലിന്റെ ഉള്ളടക്കങ്ങൾ ഉപയോക്താവ് നൽകുന്ന മെമ്മറി ബഫറിലേക്ക് ലോഡ് ചെയ്യുന്നു.savefile— ഉപയോക്താവ് നൽകുന്ന ബഫറിൽ നിന്ന് IQ (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ SD കാർഡിലെ ഒരു ഫയലിലേക്ക് ഡാറ്റ സംരക്ഷിക്കുന്നു.appendfile— ഉപയോക്താവ് നൽകിയ ബഫറിൽ നിന്ന് IQ (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ SD കാർഡിലെ നിലവിലുള്ള ഒരു ഫയലിന്റെ അവസാനം വരെ ഡാറ്റ കൂട്ടിച്ചേർക്കുന്നു.isInserted— തലച്ചോറിലേക്ക് ഒരു SD കാർഡ് ചേർത്തിട്ടുണ്ടോ എന്ന് നൽകുന്നു.size— IQ (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ SD കാർഡിൽ സംഭരിച്ചിരിക്കുന്ന ഒരു ഫയലിന്റെ വലുപ്പം നൽകുന്നു.exists— IQ (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ SD കാർഡിൽ നിർദ്ദിഷ്ട പേരുള്ള ഒരു ഫയൽ നിലവിലുണ്ടോ എന്ന് നൽകുന്നു.
SD കാർഡിൽ സംഭരിച്ചിരിക്കുന്ന .bmp, .png ഫയലുകൾ drawImageFromFile ഉപയോഗിച്ച് IQ (രണ്ടാം തലമുറ) ബ്രെയിൻ സ്ക്രീനിൽ പ്രദർശിപ്പിക്കാൻ കഴിയും, ഇത് Brain.Screen വഴി ആക്സസ് ചെയ്യപ്പെടുന്നു.
ഏതെങ്കിലും sdcard അംഗ ഫംഗ്ഷനുകൾ വിളിക്കുന്നതിന് മുമ്പ്, താഴെ കാണിച്ചിരിക്കുന്നതുപോലെ ഒരു brain ഇൻസ്റ്റൻസ് സൃഷ്ടിക്കണം:
// Create the Brain
brain Brain = brain();
loadfile#
SD കാർഡിൽ നിന്ന് ഒരു ഫയലിന്റെ ഉള്ളടക്കങ്ങൾ ഉപയോക്താവ് നൽകുന്ന മെമ്മറി ബഫറിലേക്ക് ലോഡ് ചെയ്യുന്നു.
Available Functionsint32_t loadfile(
const char* name,
uint8_t* buffer,
int32_t len );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
SD കാർഡിൽ നിന്ന് ലോഡ് ചെയ്യേണ്ട ഫയലിന്റെ പേര്. ഫയലിന്റെ പേരിൽ ഫയൽ എക്സ്റ്റൻഷൻ ഉൾപ്പെടുത്തണം. |
|
|
ഫയൽ ഡാറ്റ സൂക്ഷിക്കുന്ന ഒരു ബഫറിലേക്കുള്ള ഒരു പോയിന്റർ. |
|
|
ഫയലിൽ നിന്ന് വായിക്കേണ്ട പരമാവധി ബൈറ്റുകളുടെ എണ്ണം, സാധാരണയായി ബഫറിന്റെ വലുപ്പത്തിലേക്ക് സജ്ജീകരിച്ചിരിക്കുന്നു. |
ഫയലിൽ നിന്ന് വിജയകരമായി വായിച്ച ബൈറ്റുകളുടെ എണ്ണത്തെ പ്രതിനിധീകരിക്കുന്ന 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#
ഉപയോക്താവ് നൽകുന്ന ബഫറിൽ നിന്ന് IQ (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ 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#
ഉപയോക്താവ് നൽകുന്ന ഒരു ബഫറിൽ നിന്ന് IQ (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ SD കാർഡിലെ നിലവിലുള്ള ഒരു ഫയലിന്റെ അവസാനം വരെ ഡാറ്റ കൂട്ടിച്ചേർക്കുന്നു.
Available Functionsint32_t appendfile(
const char* name,
uint8_t* buffer,
int32_t len );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
SD കാർഡിൽ ഡാറ്റ ചേർക്കേണ്ട ഫയലിന്റെ പേര്. ഫയലിന്റെ പേരിൽ ഫയൽ എക്സ്റ്റൻഷൻ ഉൾപ്പെടുത്തണം. |
|
|
ഫയലിൽ ചേർക്കേണ്ട ഡാറ്റ അടങ്ങിയ മെമ്മറി ബഫറിലേക്കുള്ള ഒരു പോയിന്റർ. |
|
|
ബഫറിൽ നിന്ന് ഫയലിലേക്ക് കൂട്ടിച്ചേർക്കേണ്ട ബൈറ്റുകളുടെ എണ്ണം. |
ഫയലിൽ വിജയകരമായി ചേർത്ത ബൈറ്റുകളുടെ എണ്ണത്തെ പ്രതിനിധീകരിക്കുന്ന int32_t നൽകുന്നു:
എത്ര ബൈറ്റുകൾ ചേർത്തിട്ടുണ്ടെന്ന് ഒരു പോസിറ്റീവ് മൂല്യം സൂചിപ്പിക്കുന്നു.
0എന്നത് ഒരു ഡാറ്റയും ചേർത്തിട്ടില്ലെന്ന് സൂചിപ്പിക്കുന്നു.
ഫയൽ
lenനേക്കാൾ വലുതാണെങ്കിൽ, ആദ്യത്തെlenബൈറ്റുകൾ മാത്രമേ വായിക്കൂ.SD കാർഡിൽ ഫയൽ ഇതിനകം നിലവിലുണ്ടായിരിക്കണം; ഈ ഫംഗ്ഷൻ ഒരു പുതിയ ഫയൽ സൃഷ്ടിക്കുന്നില്ല.
ഈ ഫംഗ്ഷൻ മെമ്മറി അനുവദിക്കുന്നില്ല; ബഫർ ഉപയോക്താവ് സൃഷ്ടിക്കുകയും കൈകാര്യം ചെയ്യുകയും വേണം.
ഫംഗ്ഷൻ റോ ബൈറ്റുകൾ കൂട്ടിച്ചേർക്കുന്നു, ഒരു നൾ ടെർമിനേറ്റർ കൂട്ടിച്ചേർക്കുന്നില്ല.
// 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 Functionsbool isInserted();
ഈ ഫംഗ്ഷൻ ഒരു പാരാമീറ്ററുകളും സ്വീകരിക്കുന്നില്ല.
Return Valuesഒരു SD കാർഡ് ചേർത്തിട്ടുണ്ടോ എന്ന് സൂചിപ്പിക്കുന്ന ഒരു ബൂളിയൻ നൽകുന്നു:
true— IQ (രണ്ടാം തലമുറ) തലച്ചോറിൽ ഒരു SD കാർഡ് ചേർക്കുന്നു.false— SD കാർഡ് ചേർത്തിട്ടില്ല.
ഈ ഫംഗ്ഷൻ ഒരു SD കാർഡിന്റെ സാന്നിധ്യം മാത്രമേ പരിശോധിക്കുന്നുള്ളൂ; കാർഡ് ഫോർമാറ്റ് ചെയ്തതാണോ അതോ വായിക്കാൻ കഴിയുന്നതാണോ എന്ന് ഇത് പരിശോധിക്കുന്നില്ല.
// 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 (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ SD കാർഡിൽ സംഭരിച്ചിരിക്കുന്ന ഒരു ഫയലിന്റെ വലുപ്പം നൽകുന്നു.
Available Functionsint32_t size(
const char* name );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
SD കാർഡിലെ ഫയലിന്റെ പേര്. ഫയലിന്റെ പേരിൽ ഫയൽ എക്സ്റ്റൻഷൻ ഉൾപ്പെടുത്തണം. |
ഫയലിന്റെ വലുപ്പത്തെ ബൈറ്റുകളിൽ പ്രതിനിധീകരിക്കുന്ന 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#
IQ (രണ്ടാം തലമുറ) ബ്രെയിനിന്റെ SD കാർഡിൽ നിർദ്ദിഷ്ട പേരുള്ള ഒരു ഫയൽ നിലവിലുണ്ടോ എന്ന് നൽകുന്നു.
Available Functionsbool exists(
const char* name );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
SD കാർഡിൽ പരിശോധിക്കേണ്ട ഫയലിന്റെ പേര്. ഫയലിന്റെ പേരിൽ ഫയൽ എക്സ്റ്റൻഷൻ ഉൾപ്പെടുത്തണം. |
ഫയൽ നിലവിലുണ്ടോ എന്ന് സൂചിപ്പിക്കുന്ന ഒരു ബൂളിയൻ നൽകുന്നു:
true— SD കാർഡിൽ നിർദ്ദിഷ്ട പേരുള്ള ഒരു ഫയൽ നിലവിലുണ്ട്.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);
}