sveremey Posted March 15, 2019 Share Posted March 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 Link to comment Share on other sites More sharing options...
Omron Forums Support Posted March 26, 2019 Share Posted March 26, 2019 Steve, Try this, it's working on my CK3E. 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); } Link to comment Share on other sites More sharing options...
illop Posted April 11, 2019 Share Posted April 11, 2019 Hi Eric Where can I get some documents or examples related to the logging on USB in C-app? Link to comment Share on other sites More sharing options...
Omron Forums Support Posted April 29, 2019 Share Posted April 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 [FILE REMOVED] 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. Link to comment Share on other sites More sharing options...
Recommended Posts