Page 1 of 1

Is it possible to detect whether the PC is running?

Posted: Tue Jun 07, 2011 10:56 pm
by Micha
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

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

Posted: Wed Jun 08, 2011 4:00 am
by ulao
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(); }

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

Posted: Wed Jun 08, 2011 7:30 am
by Micha
How long must I monitor USB- to be sure that there's no communication? Is there any time constant?

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

Posted: Wed Jun 08, 2011 2:30 pm
by ulao
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.

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

Posted: Thu Jun 09, 2011 9:18 am
by Micha
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.

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

Posted: Thu Jun 09, 2011 2:29 pm
by ulao
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.

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

Posted: Fri Jun 10, 2011 10:58 am
by Daid
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.

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

Posted: Mon Jan 02, 2012 9:09 am
by schwa226
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.