I'm trying to determine if and when an USB stick is plugged in a BeagleBoneBlack USB port.
The stick will always be "/dev/sda1", so i thought that i could poll that file with a 1s timer (i feel this method really ... primitive? but i can't sort out anything better).
But wxFileExist("/dev/sda1") always fails, 'cause it returns wxFileSystemObjectExists(filePath, wxFILE_EXISTS_REGULAR) while seems that i should check for wxFILE_EXISTS_DEVICE, if not for wxFILE_EXISTS_ANY.
Problem is that wxFileSystemObjectExists is'nt declared in any .h file, so i can't call it directly.
1a) How am i supposed to check if a file in /dev/ exists?
Or, if my approach is wrong:
1b) How should i check for a device?
Or/and, if the whole logic is bad:
2) How can i "react" to the insertion of a USB stick?
How to react to a USB stick plugged? Or how to check if a file exists in /dev/?
Re: How to react to a USB stick plugged? Or how to check if a file exists in /dev/?
Hello,
wouldn't be better to use wxDir to check the item inside the directory?
if you check the content of /dev it should return the item inside it.
Maybe there is a better way to check if an usb is plugged in...
Best Regards,
Nicola.
wouldn't be better to use wxDir to check the item inside the directory?
if you check the content of /dev it should return the item inside it.
Maybe there is a better way to check if an usb is plugged in...
Best Regards,
Nicola.
-
- Earned some good credits
- Posts: 100
- Joined: Sun Jun 27, 2010 6:18 pm
Re: How to react to a USB stick plugged? Or how to check if a file exists in /dev/?
We periodically check this and never had any problems with it:
Code: Select all
wxFindFirstFile("/dev/sd??")
Re: How to react to a USB stick plugged? Or how to check if a file exists in /dev/?
Hi,
In my code I periodically check /sys/bus/scsi/devices. However that was written >10 years ago and, while it still works, I'm sure that nowadays there are better ways; one of which is probably libusb, which someone on #wxwidgets mentioned recently.
Regards,
David
In my code I periodically check /sys/bus/scsi/devices. However that was written >10 years ago and, while it still works, I'm sure that nowadays there are better ways; one of which is probably libusb, which someone on #wxwidgets mentioned recently.
Regards,
David
Re: How to react to a USB stick plugged? Or how to check if a file exists in /dev/?
THANKS!!!Big Muscle wrote: ↑Wed Nov 13, 2019 11:27 am We periodically check this and never had any problems with it:Code: Select all
wxFindFirstFile("/dev/sd??")
That works... i did'nt found that function.
I "solved" by using
Code: Select all
wxFileName fn("/etc/sda1");
if ( fn.Exists(wxFILE_EXISTS_ANY) ) {
Thanks again .
Seems interesting, i'll take a look at it when i can spend some time on it. Thanks.
Re: How to react to a USB stick plugged? Or how to check if a file exists in /dev/?
I don't know if wxFileSystemWatcher works for virtual filesystems, but it might be worth a try:
https://docs.wxwidgets.org/trunk/classw ... tcher.html
https://docs.wxwidgets.org/trunk/classw ... tcher.html
Use the source, Luke!
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: How to react to a USB stick plugged? Or how to check if a file exists in /dev/?
would suggest you look at libusb. I have not checked it myself but it seems have such an event. See http://libusb.sourceforge.net/api-1.0/hotplug.html
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?