Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a bit of a strange issue that I cannot get around.
I am using an SBC that has an on board sd card. I regularly store data on the sd card that I later download by plugging the SBC into my PC via a USB connection, the sd card appears as a storage device on my PC and I copy the data to my PC.
If I plug the SBC into my PC and power it up, I would like it to pause data collection until I am finished accessing the sd card. When the PC is disconnected, I can reset the SBC and data collection can resume.
Is there a way (using a script) that the SBC can detect if it is plugged into a USB host and/or its sd card is being accessed? I'd like to use this information to decide my actions on boot/power-up. ie. No USB host connected, continue normal operations. If the USB host (PC) is connected, halt data collection until next reboot.
"it" is the SBC. The SBC is the USB slave device when plugged into the USB host (the PC). The PC plugs into the SBC via a USB connection to download data from the SBC's sdcard. I would like to know if I can detect (on the SBC), using some sort of script, if the SBC is plugged into a USB host (the PC) on boot-up/power-up.
It's linux so it is possible. I would take the simplest approach and use what the kernel reports as the SBC boots. Compare the USB strings with and without PC attached. But how early in the boot cycle and what do you need to do? Answer that and then you may have to do something else than what I suggest. You can also use lsusb and check for the PC.
As usual there are multiple ways to do it and it depends on things.
Well it is not only in the boot cycle that this information is required. Often, the PC's USB cable is only plugged into the SBC after the SBC has already booted and it may be just waking from a low power mode.
I tried the lsusb command. It doesn't seem to work on my device. Just returns a statement that no devices were found in "/sys/bus/devices/usb". Since the PC is acting as the USB host and the SBC is acting as a USB slave, just looking like a memory device to the PC, should lsusb still show a connection?
Thanks.
Last edited by merlepittman; 09-06-2016 at 07:41 AM.
Without knowing anything about your device it is impossible to say if there is a way. However, considering that just about every piece of commercial hardware I have played with does detect when plugged into a PC and performs some action should be some indication that it is.
There has to be some process whether it is the operating system or separate hardware that responds to the PC during USB enumeration and data commands. As suggested look at the output of the dmesg command and running processes to see what happens when you plug it into the PC. That might provide a clue as to where you might be able to stick some code to stop recording.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.