Jump to content
OMRON Forums

Checking for USB drive from code


Recommended Posts


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;




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

  • 2 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 weeks later...
  • 3 weeks later...

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

This topic is now closed to further replies.

  • Create New...