Delta Tau Forums
Checking for USB drive from code - Printable Version

+- Delta Tau Forums (http://forums.deltatau.com)
+-- Forum: Delta Tau Data Systems (http://forums.deltatau.com/forumdisplay.php?fid=1)
+--- Forum: Power PMAC (http://forums.deltatau.com/forumdisplay.php?fid=2)
+--- Thread: Checking for USB drive from code (/showthread.php?tid=2855)



Checking for USB drive from code - sveremey - 03-15-2019

Hello,
I have an application where we are logging data to a text file on a USB drive at /media/disk-0/

This is working, the file is generated correctly. However, I need to know if the USB drive is connected or not. If I try to write the file when there is no drive I get some watchdog issues in the background.

So, can anyone tell me how to detect this drive? I don't care if it is through PMAC script or C code, either will do. I don't need millisecond frequency checking either, I can schedule it every second or so.

I have tried stat() and it seems to always say the directory is present even when the drive is removed. so this doesn't work:

struct stat st;
if(stat("/media/disk-0/",&st) == 0)
{
bUSB_Ready = 1;
}
else
{
bUSB_Ready = 0;
}

I've also tried adding a directory in the root of the USB drive, I can tell the customer they need that for it to work (so it would be /media/disk-0/LOGS or whatever). When I try to detect that I never see the drive, even when it is plugged in.

Ideas welcome!

Thanks, Steve


RE: Checking for USB drive from code - Eric Hotchkiss - 03-26-2019

Steve,

Try this, it's working on my CK3E.

Code:
char bUSB_Ready = 0;
FILE *f = popen("mount | grep /media/disk-0", "r");
if (NULL != f)
{
       /* test if something has been outputed by
       the command */
       if (EOF == fgetc(f)) {}
       else
       {
             bUSB_Ready = 1;
       }        
       /* close the command file */
       pclose(f);        
}



RE: Checking for USB drive from code - illop - 04-11-2019

Hi Eric

Where can I get some documents or examples related to the logging on USB in C-app?


RE: Checking for USB drive from code - Eric Hotchkiss - 04-29-2019

We have an example in this App note.
http://forums.deltatau.com/filedepot/download.php?f=Power%20PMAC/Application%20Notes/Saving%20Files%20on%20Power%20PMAC%20or%20External%20Media.pdf

Look at the "Saving Files on External Flash Devices" section starting on page 3.

At one point the app note instructs you to connect over telnet by typing a command windows command. I would suggest connecting with SSH through putty instead. Telnet may be disabled on newer form factors with the expectation that SSH will be used instead.