LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This 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


Reply
  Search this Thread
Old 08-31-2016, 01:48 PM   #1
merlepittman
LQ Newbie
 
Registered: Aug 2016
Posts: 3

Rep: Reputation: Disabled
detecting USB host accessing SD Card


Hi All,

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.

Thanks.
 
Old 08-31-2016, 02:32 PM   #2
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
You used the word "it" a lot so I'm not clear on what you're asking.
 
Old 09-01-2016, 07:43 AM   #3
merlepittman
LQ Newbie
 
Registered: Aug 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
"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.
 
Old 09-01-2016, 06:16 PM   #4
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
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.
 
Old 09-06-2016, 07:40 AM   #5
merlepittman
LQ Newbie
 
Registered: Aug 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello,

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.
 
Old 09-06-2016, 10:13 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB devices stop detecting (or un-detecting). Mleahy Linux - Desktop 1 07-31-2011 02:08 AM
[SOLVED] USB data card is not detecting in 2.6.36 kernel mvkrishna86 Linux - Newbie 2 01-11-2011 11:58 PM
RedHat 9 is not detecting the LAN card, but Win'98 is detecting the LAN card SKYNAT Linux - Newbie 4 12-28-2007 10:25 PM
detecting NIC, USB stick and Sound card newcanontech Linux - Hardware 1 08-12-2007 09:02 PM
any test application to help detecting intrusions on a host? nedianz Linux - Security 4 07-16-2005 11:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 03:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration