Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: possible fix, err, bandaid for usb gps/touchscreen suspend/hibernate woes

  1. #1
    Maximum Bitrate zPilott's Avatar
    Join Date
    Jul 2004
    Location
    Austin
    Posts
    509

    possible fix, err, bandaid for usb gps/touchscreen suspend/hibernate woes

    My Xenarc often fails to come back from hibernation. If I unplug it and plug it back in, it is fine, or if I restart it is fine, but most of the time it wont come back on its own. I tried several different driver versions, and installing XP SP2 make it come back some of the time, but still not even most of the time.

    I had an idea that maybe I could turn it off before I go into hibernation, and turn it back on when I come back. I was looking into writing a service to do this for me, when I came across this command line utility to do some of the stuff you can do from the device manager. I also found a small script that you can run to catch suspend events. to use this script, save it to a file called SuspendEvents.vbs. the lines that begine with ' are comments and do not do anything. As it is right now the code that works with the devices is commented out, and only the message boxes telling you what is going on show up. You will want to comment the MsgBox lines out after you run it and see how it works.

    Code:
    'this line set up the event monitoring
    Set colMonitoredEvents = GetObject("winmgmts:").ExecNotificationQuery("Select * from Win32_PowerManagementEvent") 
    
    'this gets us a shell so we can run the devcon executable
    'your antivirus software may report a _malicious script error_ due to this line
    Set WshShell = WScript.CreateObject("WScript.Shell")
    
    'the script loops forever, so you will have to kill it using the task manager
    'if you want to stop it, look for wscript.exe
    Do
    'wait for the next event
    Set strLatestEvent = colMonitoredEvents.NextEvent
    Select Case strLatestEvent.EventType
    case 4
    'put code here to be executed when you go into suspend or hibernate
    MsgBox "Entering suspend."
    'this disables all devices that start with USB\VID_045* (only my usb hub)
    'WshShell.Run "C:\windows\devcon.exe disable USB\VID_045*", 0
    case 10
    'this gives you a notification that you have gone from ac to battery or vice versa
    MsgBox "Power state Changed"
    case 11
    'this event varys from computer to computer in its meaning
    MsgBox "OEMEvent"
    case 7
    'this is run whenever the computer comes back from suspend/hibernate
    'I put in a sleep here to make sure everything else was back up and running
    'before I did anything, it is probably not needed
    'this waits 5000ms (5 seconds) before doing anything
    'WScript.Sleep 5000
    MsgBox "Resuming from suspend."
    'WshShell.Run "C:\windows\devcon.exe enable USB\VID_045*", 0
    case 18
    'I dont know how this is different from the other resume, but they both always happened in my testing
    'WScript.Sleep 5000
    MsgBox "Resume Automatic happened"
    'this restarts the device, but didn't really help me
    'WshShell.Run "C:\windows\devcon.exe restart USB\VID_045*", 0
    End Select
    Loop
    if you download devcon and run it from the command line like:
    devcon status USB*
    it will give you the ids of all the active usb devices on your system. look for the id of the device that you want to do something with. copy that out to the USB\vid_045* in the script above. You can try enabling, disabling, or restaring devices. I also tried removing devices, but I couldn't figure out how to reinstall them without actually plugging it back in.


    what ended up working for me (so far) is disabling the HUB that the touchscreen is plugged in to, then enabling it when I come back from hibernate. I tried restarting when it came back from hibernation, but that didn't work for me. I also tried the same with the TS itself first, but that didn't work either.

    I put a shortcut to this script in my startup folder, so it is run everytime I restart the computer (which hopefully will be less often now). I am not an expert in vbscript, so there may be a better way of doing this, so if anyone has any suggestions, but em up, I wont be hurt


    I also want to see what I can do about finding out the state of the battery and having the script decide to go into hibernation, any idea how I can trigger hibernation from the script?

    |V1 Virtual Display|

    Hard work often pays off over time, laziness always pays off right now.

  2. #2
    Maximum Bitrate zPilott's Avatar
    Join Date
    Jul 2004
    Location
    Austin
    Posts
    509
    It looks like I can put this in the above script to automatically go into hibernate after I lose power:

    Code:
    case 10
    Set colBattery = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Battery",,48)
    For Each objItem in colBattery
    If objItem.Availability > 2 Then
    WshShell.Run "C:\windows\poweroff.exe hibernate -warn -warntime 60", 0
    End If
    Exit For
    using the utility that I got here.

    |V1 Virtual Display|

    Hard work often pays off over time, laziness always pays off right now.

  3. #3
    Raw Wave Confused's Avatar
    Join Date
    Aug 2003
    Location
    Essex, England
    Posts
    2,224
    Looks interesting Might have to use some of the VBS code in AIMEE to detect hibernate/standby

    zPilott, AIMEE already detects going to battery power, and will send your laptop to standby/hibernate etc

    Now I should be able to detect coming BACK from standby/hibernate too And of course there will be options to do certain things on standby/hibernate as well as resume


    Garry
    Co-Developer of A.I.M.E.E
    www.aimee.cc

  4. #4
    Maximum Bitrate zPilott's Avatar
    Join Date
    Jul 2004
    Location
    Austin
    Posts
    509
    I would like to put in a bit more logic in to my power settings. The alarms are nice, but they dont really help if you start at a power level below the alarm. And the timeout doesn't work with some applications running (mainly media players).

    |V1 Virtual Display|

    Hard work often pays off over time, laziness always pays off right now.

  5. #5
    Maximum Bitrate zPilott's Avatar
    Join Date
    Jul 2004
    Location
    Austin
    Posts
    509
    this is the script I am using now:
    Code:
    Set	colMonitoredEvents = GetObject("winmgmts:").ExecNotificationQuery("Select	*	from Win32_PowerManagementEvent")	
    Set	WshShell = WScript.CreateObject("WScript.Shell")
    
    Dim lastEventTime 
    lastEventTime = 0
    
    Do
    	Set	strLatestEvent = colMonitoredEvents.NextEvent
    	Select Case	strLatestEvent.EventType
    	case 4
    	  WshShell.Run "C:\windows\devcon.exe	disable	USB\VID_045*",	0
    	case 10
    	  If Timer-lastEventTime > 600 Then
    	    Set	colBattery = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select	*	from Win32_Battery",,48)
    	    For	Each objItem in	colBattery
    	      If objItem.Availability	>	2	Then
    	        WshShell.Run "C:\windows\poweroff.exe	suspend	-warn	-warntime	30",	0
    	      End	If
    	      Exit For    
    	    Next
    	    lastEventTime = Timer 
    	 End If
    	case 7
    	  WshShell.Run "C:\windows\devcon.exe	enable	USB\VID_045*", 0  
        lastEventTime = Timer   
    '	case 18
    '	  WshShell.Run "C:\windows\devcon.exe	enable	USB\VID_045*", 0  
    '    lastEventTime = Timer   
    	End	Select       
    Loop
    anyone know how I can kill a running app in this script (I want to kill poweroff on resume)

    |V1 Virtual Display|

    Hard work often pays off over time, laziness always pays off right now.

  6. #6
    Maximum Bitrate zPilott's Avatar
    Join Date
    Jul 2004
    Location
    Austin
    Posts
    509
    I am using sendkeys right now to kill the shutdown process, any better suggestions?

    Code:
    Dim lastEventTime 
    lastEventTime = 0
    
    Sub AbortSuspend
      If WshShell.AppActivate("Computer is Shutting Down") Then
        WshShell.SendKeys "{tab}{tab}~"
      End If
    End Sub
    
    Sub Enable
      AbortSuspend
      WshShell.Run "C:\windows\devcon.exe enable USB\VID_05E*", 0  
      lastEventTime = Timer   
    End Sub		
    
    Sub Disable
      WshShell.Run "C:\windows\devcon.exe disable USB\VID_05E*", 0
    End Sub
     
     
    Sub CheckBatteryStatus
      Dim delta
      delta=  Timer-lastEventTime
      If delta < 0 Then
        delta = (delta + 60*60*24)
      End If
      If delta > 600 Then
        Set colBattery = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Battery",,48)
        For Each objItem in colBattery
          If objItem.Availability > 2 Then
            WshShell.Run "C:\windows\poweroff.exe standby -warn -warntime 30",	0
          End If
          Exit For    
        Next
        lastEventTime = Timer 
      Else 
        AbortSuspend
      End If
    End Sub  
    
    
    
    
    Set colMonitoredEvents = GetObject("winmgmts:").ExecNotificationQuery("Select * from Win32_PowerManagementEvent")	
    Set WshShell = WScript.CreateObject("WScript.Shell")
    
    
    Do
      Set strLatestEvent = colMonitoredEvents.NextEvent
      Select Case strLatestEvent.EventType
      case 4
        Disable
      case 10
        CheckBatteryStatus
      case 7
        Enable
      case 18
        Enable
      End Select       
    Loop

    |V1 Virtual Display|

    Hard work often pays off over time, laziness always pays off right now.

  7. #7
    Variable Bitrate hevnsnt's Avatar
    Join Date
    Mar 2004
    Posts
    300
    Can anyone help me with Frodo's Resume function?
    USB\ROOT_HUB\4&16E5A864&0
    Name: USB Root Hub
    Driver is running.
    USB\ROOT_HUB\4&299F5909&0
    Name: USB Root Hub
    Driver is running.
    USB\ROOT_HUB\4&42BF7BF&0
    Name: USB Root Hub
    Driver is running.
    USB\ROOT_HUB20\4&1FE4011C&0
    Name: USB Root Hub
    Driver is running.
    USB\VID_05E3&PID_0701\5&1A3F51A3&0&3
    Name: USB Mass Storage Device
    Driver is running.
    USB\VID_067B&PID_2303\5&2B910C41&0&2
    Name: Prolific USB-to-Serial Comm Port (COM4)
    Driver is running.
    USB\VID_0ACE&PID_1201\5&3063F765&0&2
    Name: (ZD1201)IEEE 802.11b USB Adapter
    Driver is running.
    USB\VID_0EEF&PID_0001\5&2B910C41&0&1
    Name: Touchkit USB Controller for TouchScreen
    Driver is running.
    USBSTOR\CDROM&VEN_MAT****A&PROD_CD-RW__CW-8123&REV_CZ24\6&355F2B22&0
    Name: MAT****A CD-RW CW-8123 USB Device
    Driver is running.
    www.i-hacked.com Hardware hacking articles

  8. #8
    Variable Bitrate
    Join Date
    Apr 2001
    Location
    NJ, USA
    Posts
    242
    You sure you won't lose your touchscreen by power cycling it? On mine the touch doesn't come back if I power cycle the screen.
    P4 2.4GHz, Intel mobo w/onboard sound & video, 128MB memory, 100GB Seagate Momentus laptop drive, Xenarc 700TSV 7" touchscreen, IRman using Girder, 150W Opus dc/dc psu, Alpine CDA-9835 h/u, MBQuart speakers, Infinity 15" sub, MTX amps.

  9. #9
    Maximum Bitrate zPilott's Avatar
    Join Date
    Jul 2004
    Location
    Austin
    Posts
    509
    I am not directly power cycling the screen (it turns off and on with the car). This basically unplugs all the devices plugged in to the hub, then plugs them all back in again when the computer comes back from hibernation

    |V1 Virtual Display|

    Hard work often pays off over time, laziness always pays off right now.

  10. #10
    Variable Bitrate skippy911's Avatar
    Join Date
    Feb 2005
    Posts
    440
    Hi awesome script. I almost have it doing what I want, wheni turn off my car it disables my gps and goes into hibernate. When I start the car it comes out of hibernate just fine but it wont reenable the gps for some reason. Also I think my select statement is wrong because it hibernates once more after the car is on and then it is fine (still no gps on ofcourse ). Oh and i replaced the power line with this:

    WshShell.Run "rundll32 powrprof.dll,SetSuspendState", 0

    No need to use a 3rd party program

    --------------------------------------------------------------------------

    'this line set up the event monitoring
    Set colMonitoredEvents = GetObject("winmgmts:").ExecNotificationQuery("Sele ct * from Win32_PowerManagementEvent")

    'this gets us a shell so we can run the devcon executable
    'your antivirus software may report a _malicious script error_ due to this line
    Set WshShell = WScript.CreateObject("WScript.Shell")

    'the script loops forever, so you will have to kill it using the task manager
    'if you want to stop it, look for wscript.exe
    Do
    'wait for the next event
    Set strLatestEvent = colMonitoredEvents.NextEvent
    Select Case strLatestEvent.EventType
    case 4
    WshShell.Run "c:\devcon disable USB\Vid_067b*", 0
    case 10
    Set colBattery = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Se lect * from Win32_Battery",,48)
    For Each objItem in colBattery
    If objItem.Availability > 2 Then
    WshShell.Run "c:\devcon disable USB\Vid_067b*", 0
    WScript.Sleep 5000
    WshShell.Run "rundll32 powrprof.dll,SetSuspendState", 0
    End If
    Exit For
    Next
    case 7
    WshShell.Run "c:\devcon enable USB\Vid_067b*", 0
    End Select
    Loop

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •