Is it possible to detect whether the PC is running?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Micha

Is it possible to detect whether the PC is running?

Post by Micha » Tue Jun 07, 2011 10:56 pm

Hi everybody,

as written above I'd like to know whether it's possible to detect whether the PC, to which V-USB is connected, is running or turned off? In my application USB voltage is supplied all the time but the PC is not running all the time and I'd like to detect when it's running and when it isn't. A software solution for V-USB would be preferred.

Best regards,
Michael

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Is it possible to detect whether the PC is running?

Post by ulao » Wed Jun 08, 2011 4:00 am

Well if the voltage is applied just look at the usb (-) pin. If its constant then no data is present.

just use a function i.e. checkAlive
while (!usbInterruptIsReady()){ checkAlive(); usbPoll(); }

Micha

Re: Is it possible to detect whether the PC is running?

Post by Micha » Wed Jun 08, 2011 7:30 am

How long must I monitor USB- to be sure that there's no communication? Is there any time constant?

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Is it possible to detect whether the PC is running?

Post by ulao » Wed Jun 08, 2011 2:30 pm

Well I have found its ok to use a loop count of 5 but be sure to kill the interrupts. Since the pin (-) of the usb has a pullup it should normally be hi. I found xp can take a max loop of 20, but vista needs 5 or less.

Code: Select all

checkAlive()
{
cli();
   DDRD &= ~0x02;
   for( ; i < 5 ; i++)
   {
      //make your test...
   }
   DDRD |= 0x02;
sei();
}


A more elegant way could be to use a pin Change interrupt.

Micha

Re: Is it possible to detect whether the PC is running?

Post by Micha » Thu Jun 09, 2011 9:18 am

Do you know what happens when the PC is booting (especially XP)? Is there periodic communication? If not one would detect that the PC is turned off although it is booting at that time.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Is it possible to detect whether the PC is running?

Post by ulao » Thu Jun 09, 2011 2:29 pm

I dont think much goes on during boot. possible some driver talk as the usb device initialize but then the talk with silence I would guess.

Daid
Rank 2
Rank 2
Posts: 55
Joined: Mon Apr 18, 2011 12:19 pm

Re: Is it possible to detect whether the PC is running?

Post by Daid » Fri Jun 10, 2011 10:58 am

I think "USB_RX_USER_HOOK" is what you are looking for. Once the device has been found by the PC the PC will keep communicating with it, so if you put a timeout after the USB_RX_USER_HOOK you can detect if the PC is running and knows the device is there.

schwa226
Rank 1
Rank 1
Posts: 20
Joined: Thu Feb 11, 2010 9:20 am

Re: Is it possible to detect whether the PC is running?

Post by schwa226 » Mon Jan 02, 2012 9:09 am

Daid wrote:I think "USB_RX_USER_HOOK" is what you are looking for. Once the device has been found by the PC the PC will keep communicating with it, so if you put a timeout after the USB_RX_USER_HOOK you can detect if the PC is running and knows the device is there.


I am also looking to detect if the PC is running or not.
As I was testing the hook with USB_RX_USER_HOOK it only change the status when data transfer is done between my application and the device.
But it doesn't work if no data transfer is happening.

Post Reply