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.
if you download devcon and run it from the command line like:
'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
'wait for the next event
Set strLatestEvent = colMonitoredEvents.NextEvent
Select Case strLatestEvent.EventType
'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
'this gives you a notification that you have gone from ac to battery or vice versa
MsgBox "Power state Changed"
'this event varys from computer to computer in its meaning
'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
MsgBox "Resuming from suspend."
'WshShell.Run "C:\windows\devcon.exe enable USB\VID_045*", 0
'I dont know how this is different from the other resume, but they both always happened in my testing
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
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?