SD-Card Detection Command in PROS

I’m currently working on using the SD Card in PROS and was wondering if there is a command that returns a boolean for if the SD-Card is connected. Similar to the vex::brain::sdcard.isInserted
from the VC API. And if a function doesn’t exist a recommended way for creating my own. Thanks for any help in advance!

1069B - Argonauts

Looks like there is but we havent exposed it. If you file an issue on the PROS repository we can get that added to the next release. In the meantime, I think you should be able to just check the result of attempting to open the file (it’ll should be something invalid if there’s no SD card mounted)

1 Like

So I’m currently attempting to create my own function with the following code:

bool SDCardIsInserted(){
std::fstream m_file;"/usd/testFile.txt", std::ios::out);
m_file.close();"/usd/testFile.txt", std::ios::in);
  remove("/usd/testFile.txt"); // This is the issue 
  return true;
return false;

and when I compile the code I get this error:

Linking hot project with ./bin/cold.package.elf and libc,libm,libpros,okapilib [ERRORS]
/usr/local/Cellar/arm-gcc-bin/8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: ./firmware/libc.a(lib_a-unlinkr.o): in function `_unlink_r':
unlinkr.c:(.text._unlink_r+0x12): undefined reference to `_unlink'
collect2: error: ld returned 1 exit status

This error is due to attempting to delete the test file after detection but I can’t figure out how to solve this issue. I could solve by just not deleting the file and opening one of the permanent files but I would prefer to create a new file and then delete just in case the permanent file address/name changes. Any recommendations?

Yeah we don’t have _unlink defined. Why are you trying to delete the file?

If the SD-Card is plugged in it would create testFile.txt and then I would like to remove it. I could base the detection of a permanent file but if that file is changed(address or name) or is removed by hand the program would believe that the SD Card ins’t plugged in when it is.

IIRC there is no delete file available in the SDK, I didn’t want anyone accidentally deleting a whole bunch of important files.

1 Like

@jpearman & @hotel thanks for the input, it makes sense! Thanks you for the clarifications.

By the way, when I mentioned you could check the result of attempting to open a file, I had something like this in mind:

std::ifstream f("/usd/file.txt"); // open file for reading
if (!file) {
    // Failed to open for some reason, handle it

It appears that operator ! is overridden for the fstream family to check for the fail trait. I’d argue that you should probably be checking the success of opening a file anyway (and also it doesn’t really matter whether a file failed to open because it didn’t exist or because the SD card isn’t plugged in-- either way there’s no file).